I am wondering why when you iterate over a variable n="1 2 3"
you get this:
$ n="1 2 3"; for a in $n; do echo $a $a $a; done
1 1 1
2 2 2
3 3 3
but if you don't put the string in a variable first you get a completely different behaviour:
$ for a in "1 2 3"; do echo $a $a $a; done
1 2 3 1 2 3 1 2 3
or stranger yet:
$ for a in ""1 2 3""; do echo $a $a $a; done
1 1 1
2 2 2
3 3 3
why does it behave differently if a string is in a variable or not?
$n
and your shell is doing word splitting. Tryn="1 2 3"; for a in "$n"; do echo "$a" "$a" "$a"; done
– don_crissti May 13 '16 at 23:37