Skip to main content
Post formatting
Source Link
Nimantha
  • 6.4k
  • 6
  • 30
  • 74
$ set quick brown fox jumps

$ echo ${*: -1:1} # last argument
jumps

$ echo ${*: -1} # or simply
jumps

$ echo ${*: -2:1} # next to last
fox

The space is necessary so that it doesntdoesn't get interpreted as a default value.

Note that this is bash-only.

$ set quick brown fox jumps

$ echo ${*: -1:1} # last argument
jumps

$ echo ${*: -1} # or simply
jumps

$ echo ${*: -2:1} # next to last
fox

The space is necessary so that it doesnt get interpreted as a default value.

Note that this is bash-only.

$ set quick brown fox jumps

$ echo ${*: -1:1} # last argument
jumps

$ echo ${*: -1} # or simply
jumps

$ echo ${*: -2:1} # next to last
fox

The space is necessary so that it doesn't get interpreted as a default value.

Note that this is bash-only.

added 22 characters in body
Source Link
oguz ismail
  • 49.2k
  • 16
  • 53
  • 75
$ set quick brown fox jumps

$ echo ${*: -1:1} # last argument
jumps

$ echo ${*: -1} # or simply
jumps

$ echo ${*: -2:1} # next to last
fox

The space is necessary so that it doesnt get interpreted as a default value.

Note that this is bash-only.

$ set quick brown fox jumps

$ echo ${*: -1:1} # last argument
jumps

$ echo ${*: -1} # or simply
jumps

$ echo ${*: -2:1} # next to last
fox

The space is necessary so that it doesnt get interpreted as a default value.

$ set quick brown fox jumps

$ echo ${*: -1:1} # last argument
jumps

$ echo ${*: -1} # or simply
jumps

$ echo ${*: -2:1} # next to last
fox

The space is necessary so that it doesnt get interpreted as a default value.

Note that this is bash-only.

edited body
Source Link
Zombo
  • 1
  • 66
  • 403
  • 423
$ set quick brown fox jumps

$ echo ${@*: -1:1} # last argument
jumps

$ echo ${@*: -1} # or simply
jumps

$ echo ${@*: -2:1} # next to last
fox

The space is necessary so that it doesnt get interpreted as a default value.

$ set quick brown fox jumps

$ echo ${@: -1:1} # last argument
jumps

$ echo ${@: -1} # or simply
jumps

$ echo ${@: -2:1} # next to last
fox

The space is necessary so that it doesnt get interpreted as a default value.

$ set quick brown fox jumps

$ echo ${*: -1:1} # last argument
jumps

$ echo ${*: -1} # or simply
jumps

$ echo ${*: -2:1} # next to last
fox

The space is necessary so that it doesnt get interpreted as a default value.

deleted 8 characters in body
Source Link
Zombo
  • 1
  • 66
  • 403
  • 423
Loading
deleted 8 characters in body
Source Link
Zombo
  • 1
  • 66
  • 403
  • 423
Loading
deleted 2 characters in body
Source Link
Zombo
  • 1
  • 66
  • 403
  • 423
Loading
added 152 characters in body
Source Link
Zombo
  • 1
  • 66
  • 403
  • 423
Loading
Source Link
Zombo
  • 1
  • 66
  • 403
  • 423
Loading