The bash-5.0 manual in section 3.5.8 states the following.
After word splitting, unless the -f option has been set (see The Set Builtin), Bash scans each word for the characters ‘*’, ‘?’, and ‘[’. If one of these characters appears, then the word is regarded as a pattern, and replaced with an alphabetically sorted list of filenames matching the pattern (see Pattern Matching). If no matching filenames are found, and the shell option nullglob is disabled, the word is left unchanged. If the nullglob option is set, and no matches are found, the word is removed.
However, in my shell, activating nullglob
it seems that filename expansion kicks in also in the following case.
$ echo ${BASH_VERSION}
5.0.0(1)-release
$ shopt -s nullglob
$ FOO="/home/smith"
$ echo ${FOO//\//\\\/}
$ echo "${FOO//\//\\\/}"
\/home\/smith
Interestingly, using an older bash version I have available, a different behaviour occurs.
$ echo ${BASH_VERSION}
4.3.30(1)-release
$ shopt -s nullglob
$ FOO="/home/smith"
$ echo ${FOO//\//\\\/}
\/home\/smith
$ echo "${FOO//\//\\\/}"
\/home\/smith
Question
I would have expected no filename expansion to occur. Can you explain why echo ${FOO//\//\\\/}
does not print anything with bash 5.0?
bash
non-compliant (but backslashes in the result of unquoted expansion still required to be treated as an escape operator provided the expansion contains at least one*
,?
, or[
, which is still not what most implementations do).