Date: Wed, 19 Nov 2025 11:40:40 -0500
From: Chet Ramey <[email protected]>
Message-ID: <[email protected]>
| Sure. So what makes the most sense?
As far as examining the behaviour goes, I'm not sure anything
is better than the others.
That's why I don't really understand why everyone doesn't just
treat all the unspecified cases for $@ as if they were $* (and
when that one is unspecified, anything goes). The code is
simply easier - and given that, I can't see why it would ever
be different.
| Maybe this is one of those places where the standard has too much inside
| baseball: everyone "knows" how it's supposed to be done, so just do it that
| way and don't make it explicit.
Probably - and when writing the standard, no-one ever even considered
these cases.
| > | and the BSD sh camp, which uses spaces in the first command and
| > | `:' in the rest.
| >
| > No, it doesn't. You'd see the problem if you reordered the commands,
| > or just repeat the first one again later.
|
| It kind of does,
Not in how $@ is expanded in the cases being tested it doesn't.
| but the variance is that the BSDs make different choices
| for unspecified behavior than the other ash descendents.
The issue (for anyone not following) was the
IFS=: o=${@-x}
command in the original test. ash implemented var assigns by
expanding everything, and then assigning, which allows
a=$b b=$a
to swap the values of two variables (and more). But it also means
that you can't use a value assigned in one var assign in another one
in the same command, they need to be made separate simple commands (by
inserting a ';'). So the o=${@-x} was using the value of IFS before
the IFS=: was executed. That is why space was being used, not because
the IFS was being ignored.
The following commands "worked" because by the time they were reached,
this first assignment had taken effect, and IFS was now set to : so that
is what was used.
And as for "other ash descendents" - there are just 3 I'm aware of.
Free & Net BSD, and dash. Some time ago (for reasons I never understood)
dash changed the way var assigns were done.
| Anyway, that reduces it to two behaviors (I don't count bosh any more,
As far as how $@ expansions are done, you can still count bosh, and
still have 2 (with bosh in the ksh93/bash camp) - the difference (bug)
in bosh is with $* expansions only.
| since you can't ask the maintainer :-( ).
At one time it seemed like someone else had taken it over, but
I haven't seen any updates in ages now.
| I'll take a look at this, see what it takes,
There is no need, no-one should really be using these unspecified
$@ variants anyway, it is just cargo-cult ... people see $@ used
(as in "$@" it is truly useful) and $* used a lot less, so they
just use $@, even when it makes no sense. Better doc might help,
and if it doesn't already shellcheck (or whatever that is called)
could diagnose improper use of $@.
Not writing the code with yet another different case in the first
place makes sense to me - but once written, going back and changing
it for no particularly good reason (even if doing so simplifies it,
which it certainly would not if the current way needs to be left as
an option) does not make sense.
kre