Re: Question on $@ vs $@$@

Chet Ramey <[email protected]> Wed, 14 Aug 2024 11:57:28 -0400
Newsgroups org.kernel.vger.dash
Organization ITS, Case Western Reserve University
Message-ID <[email protected]>
On 8/13/24 8:45 PM, Steffen Nurpmeso wrote:
> Hello.
> 
> I include bug-bash even though i think bash is correct, but there
> lots of people of expertise are listening, so, thus.
> Sorry for cross-posting, nonetheless.
> Given this snippet (twox() without argument it is)
> 
>    one() { echo "$# 1<$1>"; }
>    two() { one "$@"; }
>    twox() { one "$@$@"; }
>    two
>    two x
>    twox
>    twox x
> 
> i get
> 
>    $ dash shbug.sh
>    0 1<>
>    1 1<x>
>    1 1<>
>    1 1<xx>
> 
>    #?0|kent:tmp$ busybox.static sh shbug.sh
>    0 1<>
>    1 1<x>
>    1 1<>
>    1 1<xx>
> 
>    #?0|kent:tmp$ bash shbug.sh
>    0 1<>
>    1 1<x>
>    0 1<>
>    1 1<xx>

When, as in this case, the result would be split if the double quotes
weren't there, $@ within double quotes expands to nothing if there are
no positional parameters, no matter how many times it appears.

-- 
``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/
OpenPGP_signature.asc (application/pgp-signature, 203 B)
-----BEGIN PGP SIGNATURE-----

wmMEABEIACMWIQR8ATX7CIqvbGbGULm7WGnwZOp0qwUCZrzT6AUDAAAAAAAKCRC7WGnwZOp0qxGM
AJ9xI8awcWnrdeTK/uxk0d1W3YWxnQCgkU5bZQDD3lfp9iYH/JsCR1ERTYs=
=84CG
-----END PGP SIGNATURE-----