0
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

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

I have lower array which has romen numerals from i to xxix and when I give 14 (for example ) as second argument I want to reach lower[14] not lower[2] which is given by lower[$i]
@karabugra05: I'm not sure I fully understand, but I think that's what my solution is doing - please try it.
i am grateful to you,it happened,I achived my goal

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.