bug-grep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#54174: (MacOS Monterey 12.2.1: zsh): grep "string" * is interpreted


From: sur-behoffski
Subject: bug#54174: (MacOS Monterey 12.2.1: zsh): grep "string" * is interpreted as grep -V when directory has a filename "-Vfilename.ext"
Date: Mon, 28 Feb 2022 15:32:02 +1030
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.1

On 2/28/22 06:01, Marja Koivunen wrote:
> Ok. I understand it is not possible to make “-V “ instead of “-Vfilename” 
> because so many existing scripts rely on thatgrept works a certain way.
> 
> Maybe there is a way to add space after “-V “ and possibly also other options 
> that could be used as  part of a filename in some operating systems?

G'day again Marja,

[The following message is Bourne shell-specific; I haven't researched
exactly how this relates to zsh (especially the environment variable
IFS.]

--

David Wheeler's essay suggests modifying IFS (input field separator) to
exclude spaces, as these occasionally appear in filenames:

The default in the shell is:

        IFS="$(printf ' \n\t')" # space, newline and TAB

David suggests eliminating the space as a separator, as it causes
more trouble than its worth in some situations:

        IFS="$(printf '\n\t')"

Going past David's suggestion, I've found that, occasionally, usually
during debug output, I want TAB-separated words, not Newline-separated
words.  This leads to a further, optional tweak:

        IFS="$(printf '\t\n\t')"

Note that, in all of this, there is a very subtle dance going on
between two different entities:  The Grep program, and the (Bourne?)
Shell.  You need to understand what the shell is doing, before
looking at Grep's (or ant other's) dealing with the modified
command line.

An example of how subtle/difficult the interaction can be is that
the version control program Git, originally implemented as shell
scripts, was re-implemented in C, at least partially because of these
sorts of interactions.

--

[An advert for my "PosixExec.lua" add-on to "luaposix" rock deleted.]

--

Hope this helps,

s-b etc etc





reply via email to

[Prev in Thread] Current Thread [Next in Thread]