[BUG] With null IFS, ${1+$*}, ${var-$*}, etc. don't generate fields

2017-02-18 Thread Martijn Dekker
When IFS is null, unquoted $* within an unquoted substitution (e.g.
${1+$*} or ${unset_var-$*}) joins the PPs together into one field, as if
either "$*" or the whole substitution were quoted.

POSIX says the unquoted substitution is supposed to generate one field
for each positional parameter, with further field splitting inactive due
to empty IFS.

Unquoted $* outside of a substitution does this correctly; the bug only
occurs within one.

Test:

bash -c 'IFS=; set "abc" "def ghi" "jkl";
set ${1+$*}; printf "[%s]\\n" "$#" "$@"'

Actual output:
[1]
[abcdef ghijkl]

Expected output (as produced by every other shell):
[3]
[abc]
[def ghi]
[jkl]

Bug confirmed on bash 3.2.57, 4.3.30, 4.4.12.

Bug confirmed *not* present on bash 2.05b.

Thanks,

- M.



Re: [BUG] With null IFS, ${1+$*}, ${var-$*}, etc. don't generate fields

2017-02-18 Thread Chet Ramey
On 2/18/17 8:35 PM, Martijn Dekker wrote:
> When IFS is null, unquoted $* within an unquoted substitution (e.g.
> ${1+$*} or ${unset_var-$*}) joins the PPs together into one field, as if
> either "$*" or the whole substitution were quoted.
> 
> POSIX says the unquoted substitution is supposed to generate one field
> for each positional parameter, with further field splitting inactive due
> to empty IFS.

It's an interesting question.  I'm ok with looking at the context of the
surrounding brace expansion, though field splitting isn't one of the
expansions Posix lists for the `word'.  The question is how other shells
rationalize differing behavior for differing parameter expansions.  For
instance, ${a#$*} expands $* as if it were not going to undergo field
splitting:

set -- a b
IFS=
x=abc
printf "<%s>\n" ${x#$*}

where, as you note, other expansions such as ${parameter+word} and
${parameter-word} do not.

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