Skip to content

Instantly share code, notes, and snippets.

@dominiksalvet
Last active November 13, 2019 14:05
Show Gist options
  • Select an option

  • Save dominiksalvet/714b84e09389c35c55cc29e477a9f12b to your computer and use it in GitHub Desktop.

Select an option

Save dominiksalvet/714b84e09389c35c55cc29e477a9f12b to your computer and use it in GitHub Desktop.
Efficient POSIX way to get the last argument of a shell script.
#!/bin/sh
if [ "$#" -gt 0 ]; then # if any arguments
shift "$(($# - 1))" # shift to the last one
echo "$1" # print it
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment