Skip to main content
updated as suggested in comment
Source Link
Michał Šrajer
  • 31.1k
  • 7
  • 64
  • 86

Here is mine solution:

  • pretty portable (all POSIX sh, bash, ksh, zsh) should work
  • does not shift original arguments (shifts a copy).
  • does not use evil eval
  • does not iterate through the whole list
  • does not use external tools

Code:

ntharg() {
    shift $1
    echoprintf $1'%s\n' "$1"
}
LAST_ARG=`ntharg $# "$@"`

Here is mine solution:

  • pretty portable (all POSIX sh, bash, ksh, zsh) should work
  • does not shift original arguments (shifts a copy).
  • does not use evil eval
  • does not iterate through the whole list
  • does not use external tools

Code:

ntharg() {
    shift $1
    echo $1
}
LAST_ARG=`ntharg $# "$@"`

Here is mine solution:

  • pretty portable (all POSIX sh, bash, ksh, zsh) should work
  • does not shift original arguments (shifts a copy).
  • does not use evil eval
  • does not iterate through the whole list
  • does not use external tools

Code:

ntharg() {
    shift $1
    printf '%s\n' "$1"
}
LAST_ARG=`ntharg $# "$@"`
added 6 characters in body
Source Link
Michał Šrajer
  • 31.1k
  • 7
  • 64
  • 86

Here is mine solution:

  • pretty portable (all POSIX sh, bash, ksh, zsh) should work
  • does not shift original arguments (shifts a copy).
  • does not use evil eval
  • does not iterate through the whole list
  • does not use external tools

Code:

ntharg() {
    shift $1
    echo $1
}
LAST_ARG=`ntharg $# "$@"`

Here is mine solution:

  • pretty portable (all POSIX sh, bash, ksh, zsh) should work
  • does not shift original arguments (shifts copy).
  • does not use evil eval
  • does not iterate through whole list
  • does not use external tools

Code:

ntharg() {
    shift $1
    echo $1
}
LAST_ARG=`ntharg $# "$@"`

Here is mine solution:

  • pretty portable (all POSIX sh, bash, ksh, zsh) should work
  • does not shift original arguments (shifts a copy).
  • does not use evil eval
  • does not iterate through the whole list
  • does not use external tools

Code:

ntharg() {
    shift $1
    echo $1
}
LAST_ARG=`ntharg $# "$@"`
extended description
Source Link
Michał Šrajer
  • 31.1k
  • 7
  • 64
  • 86

Here is mine solution. Should be pretty portable (all POSIX sh, bash, ksh, zsh), and does not shift original arguments (shifts copy).:

  • pretty portable (all POSIX sh, bash, ksh, zsh) should work
  • does not shift original arguments (shifts copy).
  • does not use evil eval
  • does not iterate through whole list
  • does not use external tools

Code:

ntharg() {
    shift $1
    echo $1
}
LAST_ARG=`ntharg $# "$@"`

Here is mine solution. Should be pretty portable (all POSIX sh, bash, ksh, zsh), and does not shift original arguments (shifts copy).

ntharg() {
    shift $1
    echo $1
}
LAST_ARG=`ntharg $# "$@"`

Here is mine solution:

  • pretty portable (all POSIX sh, bash, ksh, zsh) should work
  • does not shift original arguments (shifts copy).
  • does not use evil eval
  • does not iterate through whole list
  • does not use external tools

Code:

ntharg() {
    shift $1
    echo $1
}
LAST_ARG=`ntharg $# "$@"`
Source Link
Michał Šrajer
  • 31.1k
  • 7
  • 64
  • 86
Loading