[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Strange behavior of IFS?
From: |
Greg Wooledge |
Subject: |
Re: Strange behavior of IFS? |
Date: |
Thu, 15 Apr 2010 10:05:46 -0400 |
User-agent: |
Mutt/1.4.2.3i |
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.