> 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
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
> 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 <net...@gclare.org.uk>
I see, it means that shell interpretes the content of IFS in terms of
its content(:), and the result is null.
thanks a lot.
I see, it means that shell interpretes the content of IFS in terms of
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...@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
>> 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.