[Top][All Lists]

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

Re: Use of $@

From: Chet Ramey
Subject: Re: Use of $@
Date: Tue, 21 Feb 2023 17:48:11 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.8.0

On 2/21/23 7:34 AM, Christof Warlich wrote:

$ index() { local e="$1"; shift; for i in "${!@}"; do [[ ${!i} != $e ]]
|| { echo $i; break; }; done; }
$ LANG=C index "xx yy" "${myarray[@]}"
bash: a bc xx yy z: invalid variable name

Can anyone spot what's wrong?

"${!@}" 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.
It is not equivalent to ${!1} ${!2} ... .

``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU

reply via email to

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