[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: |
Sun, 27 Feb 2022 09:31:13 +1030 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 |
On 2/27/22 05:03, 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” *
>
> 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 Marja,
Filename globbing is very handy, but there are a number of nasty surprises
for users that aren't wary.
David A. Wheeler has written a long essay on the surprises, and about how
to avoid them, that is highly worth reading. For example, what about a
filename that has spaces: "this has four sections.pdf"?
A LOT of interesting essays, many on security and/or F/OSS topics, are
itemised at David's home page:
https://dwheeler.com/
The essay, "Filenames and Pathnames in Shell: How to do it Correctly" is at:
https://dwheeler.com/essays/filenames-in-shell.html
Hope this helps,
sur-behoffski (Brenton Hoff)
programmer, Grouse Software