bug-bash
[Top][All Lists]
Advanced

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

Re: extra field in $* expansion when non-whitespace character in IFS


From: Chet Ramey
Subject: Re: extra field in $* expansion when non-whitespace character in IFS
Date: Mon, 10 Apr 2017 20:53:34 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.0

On 4/9/17 7:35 PM, Grisha Levit wrote:
> In most cases, removing a non-whitespace IFS character "delimits" a field
> in the sense that it terminates it, so the presence of such a character at
> the end of a field does not change its expansion:
> 
>   $ IFS=X
>   $ set -- Y; printf '<%s>' $*
>   <Y>
>   $ set -- YX; IFS=X; printf '<%s>' $*
>   <Y>
> 
> However, when a positional parameter ends with a non-whitespace IFS character
> and is followed by another positional parameter, the removal of the IFS
> character seems to create an additional field:
> 
>   $ set -- YX Y; printf '<%s>' $*
>   <Y><><Y>
> 
> Is this intentional? It sort of makes sense since $* is expanded as if it
> were $1c$2 (where c is the first character of IFS), i.e. the expansion above
> matches what is produced by
> 
>   set -- YX Y; v=$*; printf '<%s>' $v
> 
> but that doesn't seem to respect the prescribed behavior of first producing
> a field for each positional parameter, and then subjecting each field to
> field splitting.

I seem to recall this being part of a discussion on the austin group list
years ago. It had to do with the behavior of IFS as a field terminator
and non-whitespace characters in IFS creating null fields (conveniently).

The bash behavior agrees with the latest versions of dash and mksh, and
ksh93 had plenty of issues in this area (plus it doesn't seem to be under
active development, so it would not have changed as a result of any of
these discussions).  I'm going to leave things as they are.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/



reply via email to

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