bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Strange behavior of IFS?


From: Clark J. Wang
Subject: Re: Strange behavior of IFS?
Date: Thu, 15 Apr 2010 22:15:58 +0800

I see. Thank you.

On Thu, Apr 15, 2010 at 10:05 PM, Greg Wooledge <wooledg@eeg.ccf.org> wrote:
> 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.
>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]