To prevent Bash expansion from passing files starting with “-” you can use:
echo [!-]*
Which works portably in most shells, or, specific to ksh, bash, zsh:
echo !(-*)
For example: in a directory with this files
$ echo *
a b c ---corporate-discount.csv d -e --option.txt
Will list only (provided extglob
is active):
$ shopt -s extglob
$ echo !(-*)
a b c d
$ echo [!-]*
a b c d
But if what you want is to process all files while telling grep to avoid interpreting files stated with a -
as options, then just add a ./
:
grep -r "stuff" ./*
Or, if there is guarantee that no file called exactly -
exists in the files listed (grep will interpret a lonely -
as read from stdin), you can use:
grep -r -- "stuff" *
grep
that they aren't options. – DonHolgo May 17 '19 at 11:57subprocess.Popen(['grep', '-r', '-e' 'stuff', '--corporate-discount.csv'])
in Python, no bash anywhere. – Charles Duffy May 17 '19 at 15:37*
in commands. ALL of these can be avoided by using./*
instead. – Wildcard May 17 '19 at 19:57--
as an end-of-options sigil is perfectly reasonable as well; POSIX utility syntax guidelines require it to be honored; see guideline #10. (Sure, not all programs follow POSIX guidelines, but the answer is to string up the offending programs' authors and/or eject them from the industry). – Charles Duffy May 18 '19 at 17:27