bug-bash
[Top][All Lists]
Advanced

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

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


From: Martijn Dekker
Subject: Re: [BUG] With null IFS, ${1+$*}, ${var-$*}, etc. don't generate fields
Date: Mon, 27 Feb 2017 18:57:10 +0100
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.7.1

Op 24-02-17 om 21:20 schreef Grisha Levit:
> XRAT C.2.5 : Special Parameters [1] specifically addresses the case of
> ${unset_var-$*}.  The following example is provided:
> 
> set "abc" "def ghi" "jkl"
> IFS='' # null
> unset var
> printf '%s\n' ${var-$*}
> 
> abcdef ghijkl
> 
> ..which seems to contradict your proposed expected output.

Hmm. I'm pretty sure that's a bug in their provided examples.

First, bash acts differently for unquoted $* and unquoted ${var-$*} (or
${1+$*}, etc). Given an unset 'var', these should act identically. If
they don't, that's a bug either way.

Second, the cited example is contrary to the specification, which says:
"Expands to the positional parameters, starting from one, initially
producing one field for each positional parameter that is set. When the
expansion occurs in a context where field splitting will be performed,
any empty fields may be discarded and each of the non-empty fields shall
be further split as described in Field Splitting. [...]"

Well, the expansion occurs "in a context where field splitting will be
performed" because it is unquoted (the fact that IFS happens to be null
is neither here nor there; its value or lack thereof has no bearing on
the lexical context). So the non-empty fields, having been generated,
"shall be further split as described in Field Splitting", which, given
that IFS is null, is a no-op.

In other words, quoted "$*" should join the fields into one, but (given
null IFS) unquoted $* should leave the fields alone altogether.

Third, bash is the only shell to act this way, and only for the latter
case. Given the test script:

IFS=
set "abc" "def ghi" "jkl"
printf '$*: '
printf '|%s| ' $*
printf '  ${1+$*}: '
printf '|%s| ' ${1+$*}

test results for some current shells are as follows:

 bash:  $*: |abc| |def ghi| |jkl|   ${1+$*}: |abcdef ghijkl|
 dash:  $*: |abc| |def ghi| |jkl|   ${1+$*}: |abc| |def ghi| |jkl|
 yash:  $*: |abc| |def ghi| |jkl|   ${1+$*}: |abc| |def ghi| |jkl|
  zsh:  $*: |abc| |def ghi| |jkl|   ${1+$*}: |abc| |def ghi| |jkl|
ksh93:  $*: |abc| |def ghi| |jkl|   ${1+$*}: |abc| |def ghi| |jkl|
 mksh:  $*: |abc| |def ghi| |jkl|   ${1+$*}: |abc| |def ghi| |jkl|
 oksh:  $*: |abc| |def ghi| |jkl|   ${1+$*}: |abc| |def ghi| |jkl|

Hope this helps,

- M.




reply via email to

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