Re: Unexpected word splitting on $* when IFS is unset
From:
Kevin Brodsky
Subject:
Re: Unexpected word splitting on $* when IFS is unset
Date:
Wed, 21 Jun 2017 23:01:36 +0100
User-agent:
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0
On 21/06/2017 20:29, Chet Ramey wrote:
> On 6/21/17 2:43 PM, Kevin Brodsky wrote:
>
>> That is also my reading of POSIX (and that's more or less what Bash's
>> manpage says as well), but it doesn't seem to be the case (even in <=4.2):
> That's a relatively new requirement. The portion of the relevant sentence
> that reads "initially producing one field for each positional parameter
> that is set" is new as of issue 7 TC2. Without that, the splitting rules
> for $* were effectively identical whether it was quoted or not quoted --
> they were separated using the first character of $IFS. In a context where
> they were not quoted and word splitting took place, this had the side
> effect of splitting them in an unquoted context. When IFS is null, that
> resulted in no splitting.
I have to admit I am now a bit confused as to what word splitting is
supposed to happen when expanding $* (with the old and new spec). I
thought it was very simple:
* If quoted, there is no splitting whatsoever, and arguments are
concatenated into a single string.
* If not quoted, then each argument expands into a field, and all fields
are split according to IFS (i.e. no splitting if IFS is null).
IIUC, before this sentence was added, then 'IFS=""; set -- a b; nb_args
$*' should give 1, as no splitting occurs when IFS is null. However,
this not the case on Bash 4.2.
Do you have an example that results in a different number of arguments
(after splitting) between Bash 4.2 and 4.3?
> There were long discussions on the Posix list about this starting in late
> 2014, resulting in Posix interp 888.
>
>http://austingroupbugs.net/view.php?id=888
>
> There are still some cases where I haven't completely made bash conform to
> the new spec.
>
>> $ set -- 'a b'
>> $ IFS=''
>> $ nb_args $*
>> 1
>> $ nb_args $@
>> 1
> This is a different situation: when IFS is null, there is no splitting. So
> N fields are produced, one for each of N positional parameters, but they
> are not split any further.
Yes I realise now that this has to be true, as IFS being null means at
least that fields are not further split.
Kevin