I am new to Bash and I am seeing that there is automatic word splitting done by Bash:
a="1 2 3 4"
If I echo "a" by echo $a
I got 1 2 3 4
, which has done word splitting implicitly. If I loop through "a", I got 1, 2, 3, and 4 respectively.
I also read from here that
The shell scans the results of parameter expansion, command substitution, and arithmetic expansion that did not occur within double quotes for word splitting.
And I also found that if I have
b=$a;
echo "$b"
I would get
"1 2 3 4"
So, here is my problem: when is the word splitting done? does it change the string itself? Does it only take effect when I use echo
or for
(loop)?
More generally, how does bash handle it?