1

To access to the first argument of a function, I use

func() { echo $1; }

How to access directly to the last argument of a function in ash?

I do not want to use loops neither functions or complicated commands

0

1 Answer 1

1

You can use $($#).

$# is the number of arguments (which is equal to the index of the last argument), so $($#) is the last argument.

3
  • If you have to enter 25 space characters before your final question mark, that's a very good indication that your answer is not an answer. Use words to explain what you mean by those 4 characters.
    – jbaums
    Commented Feb 20, 2015 at 10:30
  • There's nothing much to explain : $# is the number of arguments, which is the index of the last argument, so $($#) is the last argument.
    – sssss
    Commented Feb 20, 2015 at 10:37
  • This is wrong. Round parentheses are used for command substitution. In theory, ${$#} with curly brackets could work, but it doesn't without additional indirection (so basically eval \${$#} with all the usual caveats against eval).
    – tripleee
    Commented Apr 30, 2015 at 8:35

Not the answer you're looking for? Browse other questions tagged or ask your own question.