Nov 272007
 

Found a way to do this in a single line. Works nicely.

  7 Responses to “The last positional parameter in bash”

  1. To get the REST of the parameters:

    eval “rest=\”for d in seq 1 \$[\$# – 1]; do echo -n \\\$\$d\ ; done\””

  2. The following works better:

    eval “last=\\${$#}”

  3. Crap. It’s the following that works better:

    eval “last=\${$#}”

  4. $(echo $@ |cut -d\ -f $#)

  5. last=$(echo $@ |cut -d\ -f $#)

  6. function cu() { eval ‘lasta=$’$#’;’; echo $last; };cu a b c daaa

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">