update repository
[cmdllinux.git] / bash_n_examples / bash / array / _bash_array_stringindex.sh
blobac228d367667982d3e7a31cab3e8ec9072847c42
2 myarray=('a a' 'vv' 'vvv' 'b b' 'c c')
3 echo "${!myarray[@]}"
4 declare -g -A myarray_index
5 for i in "${!myarray[@]}"; do
6 eval myarray_index["${myarray[$i]}"]=$i
7 done
9 member="vv"
11 # the "|| echo NOT FOUND" below is needed if you're using "set -e"
12 test "${myarray_index[$member]}" && echo FOUND || echo NOT FOUND
13 member="c c"
14 test "${myarray_index[$member]}" && echo FOUND || echo NOT FOUND
15 test "${myarray_index[a a]}" && echo FOUND || echo NOT FOUND
16 echo "${myarray_index[$member]}"
17 echo "${myarray_index[a a]}"
18 echo "${myarray_index[a]}"