[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Use of $@
From: |
Christof Warlich |
Subject: |
Re: Use of $@ |
Date: |
Tue, 21 Feb 2023 13:34:37 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 |
Am 21.02.23 um 12:06 schrieb Koichi Murase:
It is easy to rewrite the shell function `index' using shift as
Andreas suggests,
Yes, that's probably the solution that I'm going to choose :-).
And, by the way, also thanks to Kerin for pointing out the issue with
sparse arrays, although my use case (currently) would not be affected.
but I assume your true question is about the way to
access $@ with a specified index. You can use ${!i}. Or if you would
like to extract multiple words in a range, you can use
"${@:i:length}".
Nevertheless, thanks a lot for getting back to my _real_ question w.r.t.
the usage of $@ compared to a named array: I tried your suggestion
before already, but without success. This is what I tried and what I
would have expected to work:
$ 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?
--
Koichi
- Use of $@, Christof Warlich, 2023/02/21
- Re: Use of $@, alex xmb ratchev, 2023/02/21
- Re: Use of $@, Andreas Kusalananda Kähäri, 2023/02/21
- Re: Use of $@, Kerin Millar, 2023/02/21
- Re: Use of $@, Koichi Murase, 2023/02/21
- Re: Use of $@,
Christof Warlich <=
- 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