0

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

Paŭlo Ebermann
  • 71,139
  • 18
  • 140
  • 206
alexarsh
  • 4,693
  • 9
  • 41
  • 50
  • 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
  • 254,755
  • 72
  • 386
  • 405
1

one way in Bash

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

or simply

echo ${@:(-2):1}
kurumi
  • 24,217
  • 4
  • 43
  • 49