Re: Question on $@ vs $@$@

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

 



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.




[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux