printing last argument in shell script

All,

I am having a shell script and i will pass different argument diferent time . Please tell me how can i find the last argument that i passsed each time when i exec the script.

Thanks,
Arun.

I think, you have to redirect the value of argument to file
and then echo(by command cat) it where do you want.

why?

'man ksh' yields the following:

  Parameters Set by Shell
     The following parameters are automatically set by the shell:

     #         The number of positional parameters in decimal.

You can do something like this :

echo "Argument count = $#"
if [ $# -gt 0 ]
then
   eval last_arg=\$$#
else
   last_arg='<none>'
fi
echo "Last argument  = $last_arg"

Jean-Pierre.

With bash version 3.0 or higher you can use

${BASH_ARGV[0]}

This little explanation is of courtesy Dark_Helmet over at linxquestions.org

echo "$`echo $#`"