The last positional parameter in bash

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

eval "last=\\${$#}"
This entry was posted in Linux. Bookmark the permalink.

7 Responses to The last positional parameter in bash

  1. rocket says:

    To get the REST of the parameters:

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

  2. Tomas Pospisek says:

    The following works better:

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

  3. Tomas Pospisek says:

    Crap. It’s the following that works better:

    eval “last=\${$#}”

  4. nyighaj says:

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

  5. nyighaj says:

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

  6. marco says:

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

Leave a Reply

Your email address will not be published. Required fields are marked *

*

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