help-bash
[Top][All Lists]
Advanced

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

Re: Use of $@


From: Christof Warlich
Subject: Re: Use of $@
Date: Thu, 23 Feb 2023 13:29:39 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1

Am 21.02.23 um 23:48 schrieb Chet Ramey:
"${!@}" is not a useful expansion. It ends up being indirect expansion,
since it's not defined to do anything else, and "$@" in a context where
word splitting doesn't take place rarely expands to a usable variable
name.
Yes, I got that :-).
It is not equivalent to ${!1} ${!2} ... .

I would have assumes it to iterate over the indices of "$@", in the same
way as for the array a=(hi ho), ${!a[@]} iterates over the indices of
"${a[@]}":

$ a=(hi ho)
$ for i in "${!a[@]}"; do echo $i; done
0
1

... 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?





reply via email to

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