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.
From: Seebs on
On 2009-12-04, Parmenides <mobile.parmenides(a)gmail.com> wrote:
> IFS=:
> echo $IFS # the result is space
> echo "$IFS" # the result is :
> Is there any difference between $IFS and "$IFS"

Well, without quotes, the expansion of $IFS is subject to field splitting,
meaning that any characters in $IFS can be replaced by nulls which implicitly
separate fields.

So when you echo $IFS without quotes, it expands to a colon, and is then
separated out into fields, where a field is anything other than colons,
separated by any colons. Which means that it ends up being no arguments
at all. So you're doing echo with no argument.

-s
--
Copyright 2009, all wrongs reversed. Peter Seebach / usenet-nospam(a)seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
From: Sven Mascheck on
Geoff Clare wrote:
> Stephane Chazelas wrote:
>

>> For some shells, IFS is a field separator (zsh, pdksh, ash),
>> and for some, it's a field terminator (bash, AT&T ksh).
>> POSIX [...]

> [...] says the characters in IFS are used as field terminators.

And adding to Stephane's results:
- field separator in earlier posh and earlier ash
- field terminator since posh-0.6.15, since early
(d)ash-0.4.x, ~NetBSD3.1, and in mksh

There are even more variations, probably only important to notice
for such experiments: if the variable contains only characters from
IFS, then one field collapses in mksh and recent posh, or all fields
collapse in Bourne shell and bash-1.05. But such corner cases in
shell tend to be a house of cards, anyway.