The problem with `$($(echo $z))` is that it expands, first to `$(1)` (if `$z` is 1) and then the shell tries to run `1` as a command.
* * *
Assuming `bash`:
params=( "$@" )
for (( i = 0; i < ${#params[@]}; ++i )); do
printf 'Param %d is "%s"\
' "$i" "${params[i]}"
done
Running it:
$ bash script.sh a b c
Param 0 is "a"
Param 1 is "b"
Param 2 is "c"
Or, with `/bin/sh`:
i=0
while [ "$#" -gt 0 ]; do
printf 'Param %d is "%s"\
' "$i" "$1"
i=$(( i + 1 ))
shift
done
Running that:
$ /bin/sh script.sh a b c
Param 0 is "a"
Param 1 is "b"
Param 2 is "c"
That's if you really need to explicitly enumerate them. Usually one would just loop over `"$@"`:
for param in "$@"; do
printf 'Param: "%s"\
' "$param"
# do other thing with "$param" here
done