On Thu, Apr 15, 2010 at 09:58:42PM +0800, Clark J. Wang wrote: > # cat foo.sh > string=aa:bb:cc > oldIFS=$IFS > IFS=: > for i in "$string"; do > echo $i > done > IFS=$oldIFS > # bash foo.sh > aa bb cc > # > > I don't understand why the $string was still splitted into words since > it's double quoted. Anyone can give a reasonable explanation?
It was not split when you double quoted it. It was split when you failed to quote it in the echo command. $ string=aa:bb:cc; oIFS=$IFS; IFS=: $ for i in "$string"; do printf "<%s> " "$i"; done; echo <aa:bb:cc> The loop iterates one time.