GNU bug report logs - #54174
(MacOS Monterey 12.2.1: zsh): grep "string" * is interpreted as grep -V when directory has a filename "-Vfilename.ext"

Previous Next

Package: grep;

Reported by: Marja Koivunen <marja <at> innomore.com>

Date: Sat, 26 Feb 2022 22:33:02 UTC

Severity: normal

Done: Bob Proulx <bob <at> proulx.com>

Bug is archived. No further changes may be made.

Full log


Message #25 received at submit <at> debbugs.gnu.org (full text, mbox):

From: sur-behoffski <sur_behoffski <at> grouse.com.au>
To: bug-grep <at> gnu.org
Subject: Re: 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
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




This bug report was last modified 3 years and 83 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.