The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 05-17-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
The conventional solution would be to put any required arguments first, and leave variable arguments last.

Code:
#!/bin/sh
file=$1
shift
echo "file is $file, remaining arguments are" "$@"
The index of the last command line argument is in $#, and you can use eval to print it.

Code:
eval echo Last argument is ${$#}
eval is tricky to learn, and you need to understand proper quoting rules etc. to use it.
Reply With Quote