bug-bash
[Top][All Lists]
Advanced

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

Re: IFS valid characters


From: Dave B
Subject: Re: IFS valid characters
Date: Mon, 16 Mar 2009 09:53:44 +0100
User-agent: Thunderbird 2.0.0.19 (X11/20090114)

Stephane CHAZELAS wrote:

> 2009-03-10, 15:43(-04), Chet Ramey:
>>> What are the valid charactes for the IFS variable? In particular, is '\0' a 
>>> valid one? 
>> Technically, yes, but in practice it's not useful.  There are too many things
>> represented as C strings to make NUL work right.
> [...]
> 
> And to answer the rest of the question. In bash, any character
> except NUL is allowed in $IFS.
> 
> Some points that should be noted:
>   - the SPC, TAB and NL characters are treated specially.
>   - contrary to in the Bourne shell, pdksh or zsh, IFS is an
>     internal field terminator, not separator ("a:b:" is split
>     into "a" and "b", not "a" and "b" and "" which makes it
>     inappropriate to split $PATH for instance) (in the Bourne
>     shell, it splits into "a" and "b" as well but that's because
>     empty elements are removed there)

It looks like an empty word is created when the separator is at the
beginning, but not when it's at the end (bash 3.2 and 4):

$ IFS=':'
$ v=":a:b"
$ arr=($v)
$ declare -p arr
declare -a arr='([0]="" [1]="a" [2]="b")'
$ v="a:b:"
$ arr=($v)
$ declare -p arr
declare -a arr='([0]="a" [1]="b")'

-- 
D.




reply via email to

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