How to get the last command line parameter?

"$#" gives the number of command-line arguments. How do you get the last command-line parameter (or any particular one determined by a variable)? I thought it would be "${$#}", but that produces something completely unexpected.

Not sure it's the best way, but...

$ cat Test
eval echo \$$#

$ ./Test a b c
c

To get the one-from-last...

eval echo \$$(($#-1))

Otherwise, simply $1, $2, $3, etc...

The completely unexpected number you mention is the process id of the "current" process.

I typically set a variable to get the last argument

let last=$#-1
echo "$last"

Both will not give the exact answer he want .Here is the solution .

                    eval echo \\$$\(\($\#\)\)

If you have more than 9 arguments, you need { }.

eval echo \${$#}

Or looping all args

while [ $# -gt 0 ]
do
      last="$1"
      shift
done

Or put args to the array

args=( "$@" )
cnt="${#args[@]}"
# 1st index 0
(( lastfld=cnt-1 ))
last="${args[$lastfld]}"
echo $last