[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 chet@case.edu http://tiswww.cwru.edu/~chet/
- Re: Use of $@, (continued)
- Re: Use of $@, Kerin Millar, 2023/02/21
- Re: Use of $@, alex xmb ratchev, 2023/02/21
- Re: Use of $@, alex xmb ratchev, 2023/02/21
- Re: Use of $@, Chris F.A. Johnson, 2023/02/21
- Re: Use of $@, alex xmb ratchev, 2023/02/21
- Re: Use of $@, Greg Wooledge, 2023/02/21
- Re: Use of $@, Greg Wooledge, 2023/02/21
- Re: Use of $@, alex xmb ratchev, 2023/02/21
- Re: Use of $@, Kerin Millar, 2023/02/21
- Re: Use of $@, Greg Wooledge, 2023/02/21
- Re: Use of $@,
Chet Ramey <=
- Re: Use of $@, Christof Warlich, 2023/02/23
- Re: Use of $@, alex xmb ratchev, 2023/02/23
- Re: Use of $@, Chet Ramey, 2023/02/23
Re: Use of $@, alex xmb ratchev, 2023/02/21
Re: Use of $@, Greg Wooledge, 2023/02/21