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

MOHAMED
  • 41,599
  • 58
  • 163
  • 268

1 Answers1

1

You can use $($#).

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

jbaums
  • 27,115
  • 5
  • 79
  • 119
sssss
  • 89
  • 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 Feb 20 '15 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 Feb 20 '15 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 Apr 30 '15 at 08:35