Found a way to do this in a single line. Works nicely.
eval "last=\\${$#}"
This entry was posted
on Tuesday, November 27th, 2007 at 2:52 pm and is filed under Linux.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.
3 Responses to “The last positional parameter in bash”
December 5th, 2007 at 6:27 pm
To get the REST of the parameters:
eval “rest=\”`for d in \`seq 1 \$[\$# - 1]\`; do echo -n \\\$\$d\ ; done`\”"
November 5th, 2008 at 5:12 pm
The following works better:
eval “last=\\${$#}”
November 5th, 2008 at 5:13 pm
Crap. It’s the following that works better:
eval “last=\${$#}”