help-bash
[Top][All Lists]
Advanced

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

Re: Use of $@


From: Chet Ramey
Subject: Re: Use of $@
Date: Thu, 23 Feb 2023 10:03:41 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.8.0

On 2/23/23 7:29 AM, Christof Warlich wrote:

... but (to me, unexpectedly) the following does not work:

$ a=(hi ho)
$ f() for i in "${!@}"; do echo $i; done
$ f "${a[@]}"
bash: hi ho: invalid variable name

Wouldn' it make sense to make "${!a[@}" and "${!@}" behave similar in
some future version of bash?

It's not very useful. The value of ${!name[@]} is twofold: indexed arrays
can be sparse, and associative arrays have arbitrary keys. Neither of
those is true of the positional parameters. The indices always go from
1 (or 0) to $#, consecutively. Why do you need a different expansion to
get that?

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]