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

Re: IFS behaviour (was: ash vs. bash)



On Fri 06 Aug 1999, Stephen Zander wrote:
> >>>>> "Paul" == Paul Slootman <paul@wau.mis.ah.nl> writes:
>     Paul> The current behaviour seems to be that IFS is only being
>     Paul> used when evaluating things the second time round;
>     Paul> i.e.. like this:
> 
>     Paul> $ IFS=":$IFS" 
>     Paul> $ set a:b:c 
>     Paul> $ echo "$1" 
>     Paul> a:b:c 
>     Paul> $ echo $1 
>     Paul> a b c
> 
> Eh? ash on my laptop gives the following
> 
> $ IFS=":$IFS"
> $ set a:b:c
> $ echo $1
> a b c
> $ echo "$1"
> a:b:c

Oh, bugger, cut & paste problem (I pasted the output in the wrong order).

Anyway, my point was that if ':' is contained in IFS,

    set a:b:c

should set THREE arguments, and $1 (quoted or not) should always contain
'a', $2 should be 'b', and $3 should be 'c'.  That's the way the
original Bourne shell did it, and how the /bin/sh on Solaris still does
it. ksh, ash, and bash all do it differently however.

Here's the relevant quote from the ash manpage thats (in my
understanding of it) supports my argument:

   White Space Splitting (Field Splitting)
     After parameter expansion, command substitution, and arithmetic expansion
     the shell scans the results of expansions and substitutions that did not
     occur in double-quotes for field splitting and multiple fields can re­
     sult.

     The shell treats each character of the IFS as a delimiter and use the de­
     limiters to split the results of parameter expansion and command substi­
     tution into fields.


Paul Slootman
-- 
home:   paul@wurtel.demon.nl    http://www.wurtel.demon.nl/
debian: paul@debian.org      isdn4linux: paul@isdn4linux.de
work:   paul@murphy.nl       Murphy Software, Enschede,  NL


Reply to: