From: johnny on
Hi. I have read some messages here, and I find many of them using IFS
variable. What s te main purpose of this variable ? Where could I find
more info on this ? and examples ?
From: Dave Kelly on
johnny wrote:
> Hi. I have read some messages here, and I find many of them using IFS
> variable. What s te main purpose of this variable ? Where could I find
> more info on this ? and examples ?

http://advbash.activeventure.net/index.html

From: Stephane CHAZELAS on
2006-06-17, 23:09(+02), johnny:
> Hi. I have read some messages here, and I find many of them using IFS
> variable. What s te main purpose of this variable ? Where could I find
> more info on this ? and examples ?

The internal field separator.

This variable is used to specify how you want the word splitting
to be done, for the read command and when you ask a variable
expansion or a command substitution to be split (when you leave
$var or `cmd` or $(cmd) (and also with some shells like bash
$((arithmetics))) unquoted) in list contexts.

As in

read a b

or

echo $var

or:

echo $(cmd)

or

echo `cmd`

The first character of $IFS is also used to build $* (and
${var[*]} for shells supporting arrays).

zsh doesn't do word splitting implicitely on variable expansion,
with that shell, you need to request word splitting by using the
$=var syntax (you can see scisors there) instead of $var.

The exact way the splitting is done can be quite complex and
varies slightly from shell to shell (the POSIX specification is
not very clear on it).

The default value of $IFS is "<Space><Tab><Newline>" except for
zsh where it is "<Space><Tab><Newline><Nul>" (other shells don't
support the NUL character).

POSIX requires it to be "<Space><Tab><Newline>" or unset by
default (an unset $IFS has the same effect as a $IFS with the
default value).

--
St?phane
 | 
Pages: 1
Prev: awk with sub
Next: grep exact PID