From Bash Reference Manual
Rule from Word Splitting section:
The shell scans the results of parameter expansion, command substitution, and arithmetic expansion that did not occur within double quotes for word splitting.
Rule from Filename Expansion section:
After word splitting, unless the -f option has been set (see Section 4.3.1 [The Set Builtin], page 58), 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
So after parameter expansion, command substitution, and arithmetic expansion, word splitting happens unless on the parts within double quotes.
In
[[ ... ]]
, Giles and John1024 both said that word splitting and filename expansion don't apply to the conditional expression within[[ ... ]]
. Which rules in the Bash Reference Manual or POSIX 7 Specifications govern that?The conditional expression within
[[ ... ]]
isn't double quoted, so why doesn't word splitting apply?The
-f
option isn't set. Why does filename expansion not apply either?
Besides
[[ ... ]]
, are there other cases where word splitting, filename expansion, or both don't apply? Are their reasons that one or both of the two don't apply the same as[[..]]
?Do word splitting and filename expansion always go hand in hand, in the sense that they either both apply or both don't apply to each case?
[
and[[
is that[
is a command (whether built in or not) while[[
is a shell keyword. See also Differences between keyword, reserved word, and builtin?LESS='+/^SHELL GRAMMAR' man bash
The command[
begins a "simple command"; the keyword[[
begins a "compound command." They have different rules for how they are expanded, that's all.