Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Do I Find the Last Positional Parameter in Linux

Tags:

linux

bash

I am looking to find the last positional parameter. I know to find the number of parameters is $# which logically is the last but I need to find and use what is in the last positional parameter.

It would be like if $# = 5, I want to do $5.

I have tried to do something like $$# or ${$#} as guesses but can't get it.

Instances where I would need to use it is in an if statement or declaring it to another variable or with echo.

I hope that is clear. Thanks in advance.

like image 737
leeman24 Avatar asked Apr 02 '12 02:04

leeman24


1 Answers

You want ${!#}, which combines the argument count with indirection.

like image 186
Ignacio Vazquez-Abrams Avatar answered Oct 04 '22 18:10

Ignacio Vazquez-Abrams