The last positional parameter in bash

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

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

3 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=\${$#}”

Leave a Reply