[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Use of $@
From: |
Christof Warlich |
Subject: |
Use of $@ |
Date: |
Tue, 21 Feb 2023 11:27:36 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 |
Hi,
just to improve my bash skills: The following functions prints the array
index of a value if found:
index() { local e="$1"; shift; local a=("$@"); for i in "${!a[@]}"; do
[[ ${a[$i]} != $e ]] || { echo $i; break; }; done; }
Thus, with e.g.: myarray=("a" "bc" "my value" "z")
I get:
$ index "my value" "${myarray[@]}"
2
as expected. The only thing that bothers me is that I couldn't get away
without the intermediate assignment of $@ to a new array (a): Is there
really no way to avoid that, i.e. directly using $@ in the for-loop?
Cheers,
Chris
- Use of $@,
Christof Warlich <=