That's a known misfeature of GNU getopt
(used for option parsing by GNU tools).
grep hi -vR
is required by POSIX to look for hi
in the file called -vR
as options many not be recognised past non-option arguments (like hi
here).
Most GNU tools or tools making use or the GNU getopt
API in the default mode don't honour that unless POSIXLY_CORRECT
is in the environment.
So you need either:
POSIXLY_CORRECT=1 grep hi *
(force grep
to behave in a POSIX compliant way) or
grep -- hi *
(explicitly mark the end of options with --
) or
grep hi ./*
(make sure all file names start with ./
, and so not -
).
In any case, with:
grep -e hi -vR
you'd have the problem with GNU and non-GNU grep
as that hi
is not a non-option argument, but an argument to the -e
option, so you'd need:
grep -e hi -- *
or (better as it also addresses the problem of a file called -
):
grep -e hi ./*
(POSIXLY_CORRECT wouldn't help).