Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: egrep --color=always 'zsh\.'



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




Messages sorted by: Reverse Date, Date, Thread, Author