Wednesday, 28 August 2013

bash word splitting mechanism

bash word splitting mechanism

pI 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. /p pI also read from a
href=https://www.gnu.org/software/bash/manual/html_node/Word-Splitting.html#Word-Splitting
rel=nofollowhttps://www.gnu.org/software/bash/manual/html_node/Word-Splitting.html#Word-Splitting/a
that/p
blockquote pThe shell scans the results of parameter expansion,
command substitution, and arithmetic expansion that did not occur within
double quotes for word splitting./p /blockquote pAnd I also found that if
I have b=$a; echo $b/p pI would get 1 2 3 4/p pSo, 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 general, how does
bash handle it on earth?/p pGreat thanks!!/p

No comments:

Post a Comment