2017-03-06 16:44:01 -0600, Eric Blake:
[...]
> > To reproduce run in empty directory
> > 
> > echo "start_string_20091210.end" | grep -o
> > [1-2][0][0-1][0-9][0-1][0-9][0-3][0-9]
> 
> Underquoted.  This asks the shell to perform globbing for all files that
> match those patterns.  Initially, none do, so the shell passes the
> pattern on unchanged to grep.
[...]

For completeness, that happens with most shells but not fish
where [...] is not a glob operator.

Also, with zsh, csh, tcsh and pre-Bourne shells, you would have
had a "not found" error as the glob doesn't match any file that
would have helped identify the source of problem earlier.

That was /broken/ by the Bourne shell in the late seventies that
instead passes the glob unexpanded to the command when it
doesn't match any file. All Bourne-like shells except zsh, and
rc-like shells are /broken/ in the same way. fish doesn't have
the issue (for its own globs that don't include [...]).

In recent versions of bash, you can do:

shopt -s failglob

to get the /better/ behaviour.

See also
https://unix.stackexchange.com/questions/204803/why-is-nullglob-not-default
for more information on that.

-- 
Stephane



Reply via email to