From: Parmenides on
IFS=:
echo $IFS # the result is space
echo "$IFS" # the result is :
Is there any difference between $IFS and "$IFS"
From: Andrew McDermott on
Parmenides wrote:

> IFS=:
> echo $IFS # the result is space

a space, or just a blank line?

> echo "$IFS" # the result is :
> Is there any difference between $IFS and "$IFS"

Also
$ aaa="a
> b
> c
> d
> e"
$ echo $aaa
a b c d e
$ echo "$aaa"
a
b
c
d
e

IFS is the internal field separator. When you quote a string with double
quotes it is a single token. When you don't quote a string it is broken
into tokens using IFS to identify field separators. IFS normally contains
the space, tab and newline characters, so in my example 'echo $aaaa'
becomes 'echo "a" "b" "c" "d" "e"' (ie five arguments) while 'echo "$aaa"'
contains a single argument - a string on five lines. In your example $IFS
is either being interpreted as spaces (if indeed it is printing a space),
or as a string which contains a ':'.

echo separates its arguments with a space when it prints them.

Andrew


From: Stephane Chazelas on
On 2009-12-04, Andrew McDermott <a.p.mcdermott(a)NOSPAM-rl.ac.uk> wrote:
> Parmenides wrote:
>
>> IFS=:
>> echo $IFS # the result is space
>
> a space, or just a blank line?
[...]

It will depend on the shell. For some shells, IFS is a field
separator (zsh, pdksh, ash), and for some, it's a field
terminator (bash, AT&T ksh). POSIX is not very clear what it
should be (or at least wasn't the last time I checked).

So where IFS is a separator, $IFS above is split into "" and ""
which echo outputs separated by a space. And where it's a
terminator, into just one "".

That's something to bear in mind when for instance using IFS=:
to split $PATH like variables.

--
Stephane
From: Geoff Clare on
Stephane Chazelas wrote:

> It will depend on the shell. For some shells, IFS is a field
> separator (zsh, pdksh, ash), and for some, it's a field
> terminator (bash, AT&T ksh). POSIX is not very clear what it
> should be (or at least wasn't the last time I checked).

It was clarified in the 2008 edition. (It says the characters
in IFS are used as field terminators.)

--
Geoff Clare <netnews(a)gclare.org.uk>


From: Parmenides on
On 12ÔÂ4ÈÕ, ÏÂÎç8ʱ09·Ö, Andrew McDermott <a.p.mcderm...(a)NOSPAM-rl.ac.uk>
wrote:
> Parmenides wrote:
> > IFS=:
> > echo $IFS # the result is space
>
> a space, or just a blank line?
>
> > echo "$IFS" # the result is :
> > Is there any difference between $IFS and "$IFS"
>
> Also
> $ aaa="a> b
> > c
> > d
> > e"
>
> $ echo $aaa
> a b c d e
> $ echo "$aaa"
> a
> b
> c
> d
> e
>
> IFS is the internal field separator. When you quote a string with double
> quotes it is a single token. When you don't quote a string it is broken
> into tokens using IFS to identify field separators. IFS normally contains
> the space, tab and newline characters, so in my example 'echo $aaaa'
> becomes 'echo "a" "b" "c" "d" "e"' (ie five arguments) while 'echo "$aaa"'
> contains a single argument - a string on five lines. In your example $IFS
> is either being interpreted as spaces (if indeed it is printing a space),
> or as a string which contains a ':'.
>
> echo separates its arguments with a space when it prints them.
>
> Andrew

I see, it means that shell interpretes the content of IFS in terms of
its content(:), and the result is null.
thanks a lot.