zsh-users
 help / color / mirror / code / Atom feed
* egrep --color=always 'zsh\.'
@ 2024-04-02 16:33 Ray Andrews
  2024-04-02 20:14 ` Lawrence Velázquez
  0 siblings, 1 reply; 10+ messages in thread
From: Ray Andrews @ 2024-04-02 16:33 UTC (permalink / raw)
  To: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 724 bytes --]

     % apt-file search zsh. | egrep --color=always 'zsh\.'

... if using egrep, the above makes sure that the dot is taken 
literally.  I have a function that ends up trying to create the above:

     % func 'zsh\.'

... which will attempt:

     apt-file search "$1" | egrep --color=always $1

... and it works fine unless I want to force a literal char, as above.  
zsh is removing the quotes as she properly does, but in this case I need 
to preserve them since egrep needs them.  I know I've done this before.  
Something in the (Q) continuum?  It has to be egrep since I normally 
want the regex interpretation, it's just this odd case where I need a 
regex char forced literal.   I know it's doable.




[-- Attachment #2: Type: text/html, Size: 1167 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: egrep --color=always 'zsh\.'
  2024-04-02 16:33 egrep --color=always 'zsh\.' Ray Andrews
@ 2024-04-02 20:14 ` Lawrence Velázquez
  2024-04-02 20:53   ` Ray Andrews
  2024-04-03  3:42   ` Mark J. Reed
  0 siblings, 2 replies; 10+ messages in thread
From: Lawrence Velázquez @ 2024-04-02 20:14 UTC (permalink / raw)
  To: Ray Andrews; +Cc: zsh-users

On Tue, Apr 2, 2024, at 12:33 PM, Ray Andrews wrote:
> % apt-file search zsh. | egrep --color=always 'zsh\.'
>
> ... if using egrep, the above makes sure that the dot is taken 
> literally.  I have a function that ends up trying to create the above:
>
>     % func 'zsh\.'
>
> ... which will attempt:
>
>     apt-file search "$1" | egrep --color=always $1
>
> ... and it works fine unless I want to force a literal char, as above.

The issue is probably that you are using the same pattern for both
"apt-file search" and egrep, but they don't interpret it in the
same way.  By default, "apt-file search" does a literal substring
match, so "\." will match backslash-period.

The function as presented cannot actually work with regex arguments,
so just switch to "grep -F" and avoid the escaping issues altogether.
(While apt-file does have a --regexp option, it uses Perl regexp,
not the POSIX and PCRE languages supported by GNU grep.)

	func() {
		apt-file search $1 | grep -F --color=always -- $1
	}


> zsh is removing the quotes as she properly does

Please refrain from referring to zsh as "she".  The shell is neither
a woman nor a ship.


> but in this case I need to preserve them since egrep needs them.

No, egrep does not need the quotes.


> I know I've done this 
> before.  Something in the (Q) continuum?  It has to be egrep since I 
> normally want the regex interpretation, it's just this odd case where I 
> need a regex char forced literal.   I know it's doable.

You don't have a shell issue, so this is not necessary.


-- 
vq


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: egrep --color=always 'zsh\.'
  2024-04-02 20:14 ` Lawrence Velázquez
@ 2024-04-02 20:53   ` Ray Andrews
  2024-04-02 22:45     ` Lawrence Velázquez
  2024-04-03  3:42   ` Mark J. Reed
  1 sibling, 1 reply; 10+ messages in thread
From: Ray Andrews @ 2024-04-02 20:53 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 1856 bytes --]



On 2024-04-02 13:14, Lawrence Velázquez wrote:
> The issue is probably that you are using the same pattern for both
> "apt-file search" and egrep, but they don't interpret it in the
> same way.  By default, "apt-file search" does a literal substring
> match, so "\." will match backslash-period.
Right, I know that, my code sample was too lazy.  The only issue is with 
the egrep.
> The function as presented cannot actually work with regex arguments,
> so just switch to "grep -F" and avoid the escaping issues altogether.
If there's no way for the shell to handle it, then that's just what I'll 
do.  Still .... I'm almost sure I've had to deal with this before.  IIRC 
every situation I've come up against has been handled by the right 
combination of quotes and backslashes ... I think.

> Please refrain from referring to zsh as "she". The shell is neither
> a woman nor a ship.
Sure.  But things besides ships are feminized.  Never mind.  As you wish.
> No, egrep does not need the quotes.

    % apt-file search zsh-theme | egrep --color=always zsh.
    ...
    zsh-theme-powerlevel9k: /usr/share/powerlevel9k/powerlevel9k.zsh-theme

    % apt-file search zsh-theme | egrep --color=always zsh\.
    ...
    zsh-theme-powerlevel9k: /usr/share/powerlevel9k/powerlevel9k.zsh-theme

    % apt-file search zsh-theme | egrep --color=always 'zsh.'
    ...
    zsh-theme-powerlevel9k: /usr/share/powerlevel9k/powerlevel9k.zsh-theme

    % apt-file search zsh-theme | egrep --color=always 'zsh\.'
    [ no match ]


... the dot is matching the dash -- or anything else -- unless I use:  
'zsh\.'

    % apt-file search zsh. | egrep --color=always 'zsh\.'
    ...
    zsh-doc: /usr/share/info/zsh.info.gz


... the dot is matched.  Mind, it was easy to be fooled because : egrep 
zsh.
... the dot matches any character *including* a literal dot.



[-- Attachment #2: Type: text/html, Size: 3183 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: egrep --color=always 'zsh\.'
  2024-04-02 20:53   ` Ray Andrews
@ 2024-04-02 22:45     ` Lawrence Velázquez
  2024-04-02 22:55       ` Bart Schaefer
  2024-04-02 23:26       ` Ray Andrews
  0 siblings, 2 replies; 10+ messages in thread
From: Lawrence Velázquez @ 2024-04-02 22:45 UTC (permalink / raw)
  To: zsh-users

On Tue, Apr 2, 2024, at 4:53 PM, Ray Andrews wrote:
> On 2024-04-02 13:14, Lawrence Velázquez wrote:
>> The issue is probably that you are using the same pattern for both "apt-file search" and egrep, but they don't interpret it in the
>> same way.  By default, "apt-file search" does a literal substring
>> match, so "\." will match backslash-period.
> Right, I know that, my code sample was too lazy.  The only issue is 
> with the egrep.

The solution is to stop using egrep.


>> The function as presented cannot actually work with regex arguments,
>> so just switch to "grep -F" and avoid the escaping issues altogether. If there's no way for the shell to handle it, then that's just what I'll do.

If you're going to continue using "apt-file search $1" then it
simply does not make sense for $1 to be a regex, and it follows
that it does not make sense to use "egrep $1".  Using "grep -F"
removes the need to try slicing and dicing the argument at all.

Don't use the shell to paper over bad design when you can just
fix the design.


> Still .... I'm almost sure I've had to deal with this before.  IIRC every situation I've come up against has been handled by the right combination of quotes and backslashes ... I think.

It is easy to escape characters that are special to zsh itself.
It is not so easy to escape characters that are special to POSIX
extended regex.  (The rules are hardly impossible to work out,
but they're not straightforward either.)


>> No, egrep does not need the quotes.
>> % apt-file search zsh-theme | egrep --color=always zsh. 
>> ...
>> zsh-theme-powerlevel9k: /usr/share/powerlevel9k/powerlevel9k.zsh-theme
>> 
>> % apt-file search zsh-theme | egrep --color=always zsh\.
>> ...
>> zsh-theme-powerlevel9k: /usr/share/powerlevel9k/powerlevel9k.zsh-theme
>> 
>> % apt-file search zsh-theme | egrep --color=always 'zsh.'
>> ...
>> zsh-theme-powerlevel9k: /usr/share/powerlevel9k/powerlevel9k.zsh-theme

These three commands are effectively identical; they invoke egrep
with the pattern "zsh.".


>> % apt-file search zsh-theme | egrep --color=always 'zsh\.'
>> [ no match ]
>
> ... the dot is matching the dash -- or anything else -- unless I use:  'zsh\.' 

Yes, you have to quote properly to ensure that egrep receives the
necessary "zsh\." argument -- just as with any other command.  But
egrep itself does not "need" the quotes; it does not see them at
all.  This command is uglier but works just as well:

	% apt-file search zsh-theme | egrep --color=always zsh\\.

"Preserving" the quotes, as you considered in your first message,
would in fact break the command.


-- 
vq


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: egrep --color=always 'zsh\.'
  2024-04-02 22:45     ` Lawrence Velázquez
@ 2024-04-02 22:55       ` Bart Schaefer
  2024-04-02 23:29         ` Ray Andrews
  2024-04-03  8:18         ` Lawrence Velázquez
  2024-04-02 23:26       ` Ray Andrews
  1 sibling, 2 replies; 10+ messages in thread
From: Bart Schaefer @ 2024-04-02 22:55 UTC (permalink / raw)
  To: zsh-users

On Tue, Apr 2, 2024 at 3:46 PM Lawrence Velázquez <larryv@zsh.org> wrote:
>
> On Tue, Apr 2, 2024, at 4:53 PM, Ray Andrews wrote:
> > Right, I know that, my code sample was too lazy.  The only issue is
> > with the egrep.
>
> The solution is to stop using egrep.

Consider perhaps fgrep which looks for literal strings rather than patterns.

> "Preserving" the quotes, as you considered in your first message,
> would in fact break the command.

Obviously what needed to be preserved was the backslash.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: egrep --color=always 'zsh\.'
  2024-04-02 22:45     ` Lawrence Velázquez
  2024-04-02 22:55       ` Bart Schaefer
@ 2024-04-02 23:26       ` Ray Andrews
  1 sibling, 0 replies; 10+ messages in thread
From: Ray Andrews @ 2024-04-02 23:26 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 903 bytes --]


On 2024-04-02 15:45, Lawrence Velázquez wrote:
> It is easy to escape characters that are special to zsh itself.
> It is not so easy to escape characters that are special to POSIX
> extended regex.  (The rules are hardly impossible to work out,
> but they're not straightforward either.)
I think that's the crux of it.  I do understand what you're saying. If 
there were a fix via some form of quoting or whatever, I'd use it, so I 
thought I'd ask, but as you say, there are more robust solutions.  I'm 
fishing for something easy but in practice this is hardly an issue, I'm 
just interested in the principle of the thing. I've come to learn that 
zsh can do almost anything if you get the invocation just right.

Meanwhile it would sure be nice if the world could standardize on one 
set of regex rules.  I haven't learned perl but they say it can do 
anything you could imagine doing and more.

[-- Attachment #2: Type: text/html, Size: 1378 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: egrep --color=always 'zsh\.'
  2024-04-02 22:55       ` Bart Schaefer
@ 2024-04-02 23:29         ` Ray Andrews
  2024-04-03  8:18         ` Lawrence Velázquez
  1 sibling, 0 replies; 10+ messages in thread
From: Ray Andrews @ 2024-04-02 23:29 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 283 bytes --]



On 2024-04-02 15:55, Bart Schaefer wrote:
> Obviously what needed to be preserved was the backslash.
Exactly.  This isn't worth any bother.  If there had been a fast and 
nasty CLI way of feeding egrep what it wants I'd be happy to accept it.  
If not, there are proper fixes.


[-- Attachment #2: Type: text/html, Size: 865 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: egrep --color=always 'zsh\.'
  2024-04-02 20:14 ` Lawrence Velázquez
  2024-04-02 20:53   ` Ray Andrews
@ 2024-04-03  3:42   ` Mark J. Reed
  2024-04-03 12:50     ` Ray Andrews
  1 sibling, 1 reply; 10+ messages in thread
From: Mark J. Reed @ 2024-04-03  3:42 UTC (permalink / raw)
  To: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 453 bytes --]

On Tue, Apr 2, 2024 at 4:14 PM Lawrence Velázquez <larryv@zsh.org> wrote:

> Please refrain from referring to zsh as "she".  The shell is neither a
> woman nor a ship.


That is a ridiculous request.  We use gendered pronouns for inanimate
objects all the time in English; it's purely a stylistic flourish, by no
means limited to ships. Please refrain from telling others how to express
themselves.
-- 
Mark J. Reed <markjreed@gmail.com>

[-- Attachment #2: Type: text/html, Size: 954 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: egrep --color=always 'zsh\.'
  2024-04-02 22:55       ` Bart Schaefer
  2024-04-02 23:29         ` Ray Andrews
@ 2024-04-03  8:18         ` Lawrence Velázquez
  1 sibling, 0 replies; 10+ messages in thread
From: Lawrence Velázquez @ 2024-04-03  8:18 UTC (permalink / raw)
  To: zsh-users

On Tue, Apr 2, 2024, at 6:55 PM, Bart Schaefer wrote:
> Consider perhaps fgrep which looks for literal strings rather than patterns.

Yes, although I would (and did) recommend "grep -F" because fgrep
(and egrep, for that matter) is no longer in POSIX, and recent GNU
grep prints an obsolescence warning when you invoke it as fgrep (or
egrep).

-- 
vq


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: egrep --color=always 'zsh\.'
  2024-04-03  3:42   ` Mark J. Reed
@ 2024-04-03 12:50     ` Ray Andrews
  0 siblings, 0 replies; 10+ messages in thread
From: Ray Andrews @ 2024-04-03 12:50 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 842 bytes --]



On 2024-04-02 20:42, Mark J. Reed wrote:
> On Tue, Apr 2, 2024 at 4:14 PM Lawrence Velázquez <larryv@zsh.org> wrote:
>
>     Please refrain from referring to zsh as "she".  The shell is
>     neither a woman nor a ship.
>
>
> That is a ridiculous request.  We use gendered pronouns for inanimate 
> objects all the time in English; it's purely a stylistic flourish, by 
> no means limited to ships. Please refrain from telling others how to 
> express themselves.
> -- 
> Mark J. Reed <markjreed@gmail.com>
In my case I refer to the shell in the feminine because she captivates 
me but I don't understand her, and often I don't know what she wants nor 
how to keep her happy.  However this is the most rancor-free forum I've 
ever been on so whatever keeps the peace. Besides, Lawrence has helped 
me a hundred times so I 'owe him'.

[-- Attachment #2: Type: text/html, Size: 2114 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-04-03 12:51 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-02 16:33 egrep --color=always 'zsh\.' Ray Andrews
2024-04-02 20:14 ` Lawrence Velázquez
2024-04-02 20:53   ` Ray Andrews
2024-04-02 22:45     ` Lawrence Velázquez
2024-04-02 22:55       ` Bart Schaefer
2024-04-02 23:29         ` Ray Andrews
2024-04-03  8:18         ` Lawrence Velázquez
2024-04-02 23:26       ` Ray Andrews
2024-04-03  3:42   ` Mark J. Reed
2024-04-03 12:50     ` Ray Andrews

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).