On 11/18/25 1:46 AM, Robert Elz wrote:
     Date:        Mon, 17 Nov 2025 16:28:56 -0500
     From:        Chet Ramey <[email protected]>
     Message-ID:  <[email protected]>

   | This is easy enough to fix; the pattern expansion operators didn't know
   | the expansion was taking place on the rhs of an assignment statement.

I assume that "taking place on the rhs of an assignment" you really mean
"taking place in a situation where field splitting will not occur".

In general, yes. In this particular case, the inconsistency resulted from
a flag not getting passed down to the function that implements the pattern
removal operators. It's a niche case, so it's escaped notice so far.

Once that inconsistency gets fixed, we can talk about what the `right'
behavior should be.

I also hesitate to imagine how

        echo $(( $@ ))

is intended to be parsed (similarly $@ in a here doc, except that one
is probably to be treated as an operand of a redirect and so no field
splitting).

Well, everyone (including the NetBSD sh), manages to display `11' when
given these two scripts.

$ cat x3
set -- a + b
a=4
b=7

echo $(( $@ ))
$ cat x3a
set -- 7 + 4

echo $(( $@ ))

so I'm not going to worry too much about it.


ps: personally I think the sane behaviour (also easy to implement) is to
treat (always) $@ expansions in non-field-splitting contexts exactly as
if $* had been written (in all respects).   But as above, it is unspecified,
probably because, most likely for histerical reasons, many shells ignore
IFS and just use a space as a separator for $@ in that context.  Weird.

The behavior is pretty varied. Given these four commands:

set a b c; IFS=: o=${@-x}; printf '<%s>\n' "$o"
set a b c; IFS=: o="${@-x}"; printf '<%s>\n' "$o"
set a b c; IFS=: o=${@?x}; printf '<%s>\n' "$o"
set a b c; IFS=: o="${@?x}"; printf '<%s>\n' "$o"

There's the bash/ksh93/mksh/SVR4.2 sh camp, which uses spaces (except mksh
errors on the `?' expansion); the dash/yash/zsh camp, which consistenly
uses `:'; and the BSD sh camp, which uses spaces in the first command and
`:' in the rest.

Chet

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    [email protected]    http://tiswww.cwru.edu/~chet/

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

Reply via email to