From: Greg Wooledge <greg@wooledge.org>
To: Marc Chantreux <mc@unistra.fr>
Cc: dash@vger.kernel.org, busybox@busybox.net, bug-bash@gnu.org,
Steffen Nurpmeso <steffen@sdaoden.eu>
Subject: Re: Question on $@ vs $@$@
Date: Wed, 14 Aug 2024 09:23:49 -0400 [thread overview]
Message-ID: <Zryv5acNkrImASKj@wooledge.org> (raw)
In-Reply-To: <ZrxzCOnZv-HffFuB@prometheus>
On Wed, Aug 14, 2024 at 11:04:08 +0200, Marc Chantreux wrote:
> > We know what "$@" is supposed to do. And something like "x${@}y" is
> > well-defined also -- you simply prefix "x" to the first word, and append
> > "y" to the final word.
>
> > But I don't know how "$@$@" is supposed to be interpreted. I do not see
> > anything in the official wording that explains how it should work.
>
> As the doc you just mention said: let's set A B C
>
> "x$@y" yA" "B" "Cy"
>
> So the only consistent behavior I see is
>
> "$@$@" A" "B" "CA" "B" "C"
> ^-("$3$1")
>
> "$@ $@" A" "B" "C A" "B" "C"
> ^-("$3 $1")
>
> I'm really currious: do you see another one ?
The most obvious would be to treat "$@$@" as if it were "$@" "$@",
generating exactly two words for each positional parameter.
<A> <B> <C> <A> <B> <C>
As a human trying to read this expression and figure out what it means,
I keep returning to the documentation. "... the expansion of the first
parameter is joined with the beginning part of the original word" and
"... the expansion of the last parameter is joined with the last part
of the original word".
If there are *two* instances of $@ within the same word, then the final
parameter of the *first* $@ is supposed to be "joined with the last
part of the original word". But the "last part of the original word"
is another list expansion, not a string! What does it even mean for
the final parameter to be "joined" with a list expansion?
Meanwhile, the first parameter of the *second* $@ is supposed to be
"joined with the beginning part of the original word". But the "beginning
part of the original word" is once again a list, not a string.
I can't see an unambiguous way to reconcile those.
So, neither of these results would shock me:
<A> <B> <CA B C> (treat it like "$@$*")
<A B CA> <B> <C> (treat it like "$*$@")
I also wouldn't be shocked if a shell were to say "screw this, I'm just
going to treat it like "$*$*" and give you one big word".
<A B CA B C>
I wouldn't consider that a *correct* result according to my reading of
the documentation, but also, it wouldn't shock me if some shell did it
that way out of desperation.
The documentation clearly never considered would should happen if the
script uses "$@$@", and I've gotta say, I've been doing shell stuff
for about 30 years now, and this is the first time *I've* ever seen
it come up.
I'd still love to know what the script's intent is.
next prev parent reply other threads:[~2024-08-14 13:23 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-14 0:45 Question on $@ vs $@$@ Steffen Nurpmeso
2024-08-14 2:17 ` Greg Wooledge
2024-08-14 9:04 ` Marc Chantreux
2024-08-14 13:23 ` Greg Wooledge [this message]
2024-08-14 14:51 ` Robert Elz
2024-08-15 7:14 ` Marc Chantreux
2024-08-14 14:20 ` Robert Elz
2024-08-14 14:58 ` Oğuz
2024-08-14 15:28 ` Greg Wooledge
2024-08-14 15:57 ` Chet Ramey
2024-08-14 20:05 ` Steffen Nurpmeso
2024-08-15 18:48 ` Steffen Nurpmeso
2024-08-15 21:33 ` Steffen Nurpmeso
[not found] ` <CAALKErGQcz=LS=xC544fXf9OywVmU32s1R-wSKzVTiavQTHZ6Q@mail.gmail.com>
2024-08-27 0:28 ` Steffen Nurpmeso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Zryv5acNkrImASKj@wooledge.org \
--to=greg@wooledge.org \
--cc=bug-bash@gnu.org \
--cc=busybox@busybox.net \
--cc=dash@vger.kernel.org \
--cc=mc@unistra.fr \
--cc=steffen@sdaoden.eu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox