Reputation: 55
argument_number=$#
for ((i = 2; i <= $argument_number; i++))
do
echo ${lower[$i]]}
done
I want to take argument value into array as index number for example if my second argumnet is 15 want to achive lower[15] but it gives lower[2] how can I do ,is there any suggestion,help
Upvotes: 0
Views: 44
Reputation: 437373
If I understand you correctly, the indices into array ${lower[@]}
are given by command-line arguments; in this case, you can simply use:
shift # skip the 1st argument
for index; do # this loops over all command-line arguments; same as: for index in "$@"; do
echo "${lower[index]}"
done
Note:
I've double-quoted ${lower[index]}
so as to protect the value from unwanted interpretation by the shell - unless you specifically want the shell to perform word-splitting and globbing on a variable value, you should double-quote all your variable references.
Array subscripts in Bash are evaluated in arithmetic context, which is why variable index
can be referenced without the usual $
prefix.
Upvotes: 1