The last positional parameter in bash

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

eval "last=\\${$#}"

5 Comments

  1. rocket:

    To get the REST of the parameters:

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

  2. Tomas Pospisek:

    The following works better:

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

  3. Tomas Pospisek:

    Crap. It’s the following that works better:

    eval “last=\${$#}”

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

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

Leave a comment