I\'m going through a Bash tutorial, and specifically the subject of word splitting.
This script, called \"args\", helps demonstrate word splitting examples:
You can read more about word splitting here.
The shell scans the results of parameter expansion, command substitution, and arithmetic expansion that did not occur within double quotes for word splitting.
When you pass the bare string one:two:three
as an argument with IFS set to :
, Bash doesn't do word splitting because the bare string is not one of parameter expansion, command substitution, or arithmetic expansion contexts.
However, when the same string is assigned to a variable and the variable is passed to the script unquoted, word splitting does occur as it is a case of parameter expansion.
The same thing applies to these as well (command substitution):
$ ./args $(echo one:two:three)
3 args: <one> <two> <three>
$ ./args "$(echo one:two:three)"
1 args: <one:two:three>
As documented, read
command does do word splitting on every line read, unless IFS has been set to an empty string.