From the Advanced Bash-Scripting Guide, to get the last command-line argument:
Or:
lastarg=${!#}
This is an
indirect reference to the$#
variable.
Note thatlastarg=${!$#}
doesn't work.
bash
From the Advanced Bash-Scripting Guide, to get the last command-line argument:
Or:
lastarg=${!#}
This is an
indirect reference to the$#
variable.
Note thatlastarg=${!$#}
doesn't work.
Best Answer
As it says it is an indirect reference. Take the following example:
Now if I were to set the following positional parameters:
And
$#
will represent the total number of positional parameters:This means when I call it like
${!#}
I'm saying give me the value of the parameter named3
: