[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: |
Gary Johnson |
Subject: |
bug#54174: (MacOS Monterey 12.2.1: zsh): grep "string" * is interpreted as grep -V when directory has a filename "-Vfilename.ext" |
Date: |
Sat, 26 Feb 2022 14:55:33 -0800 |
User-agent: |
Mutt/1.5.20 (2009-06-14) |
On 2022-02-26, Marja Koivunen wrote:
> I had a directory with filenames that started with “-“
>
> doing grep on that directory for a “string" did not find anything
> although “string was on some of the files”
>
> grep just kept repeating something … FreeBSD
>
> Finally, (with some help) I understood that grep interpreted “-Vfiename” as
> an option -V and
> gave the version info instead of doing grep “string” *
The usual solution for that problem is to use "--" to indicate that
the words following are file names and not options. For example, if
you execute
grep string *
in a directory containing some file names beginning with "-", those
names will be treated as options. If instead you execute
grep string -- *
then all file names will be treated as file names.
An example of this is given near the bottom of recent versions of
the grep(1) man page, under EXAMPLES.
Regards,
Gary