0

How can I get second argument from the end of arguments line in bash?

Paŭlo Ebermann
  • 73,284
  • 20
  • 146
  • 210
alexarsh
  • 5,123
  • 12
  • 42
  • 51
  • Related: http://stackoverflow.com/questions/1853946/getting-the-last-argument-passed-to-a-shell-script – moinudin Feb 28 '11 at 14:17

2 Answers2

4

To print the second last argument use:

echo "${@:(-2):1}"
dogbane
  • 266,786
  • 75
  • 396
  • 414
1

one way in Bash

set -- ${@:(-2)}
echo $1

or simply

echo ${@:(-2):1}
kurumi
  • 25,121
  • 5
  • 44
  • 52