BASH scripting: n-th parameter of $@ when the index is a variable?
You can use variable indirection. It is independent of arrays, and works fine in your example:
n=2echo "${!n}"
Edit: Variable Indirection can be used in a lot of situations. If there is a variable foobar
, then the following two variable expansions produce the same result:
$foobarname=foobar${!name}