Last active
November 13, 2019 14:05
-
-
Save dominiksalvet/714b84e09389c35c55cc29e477a9f12b to your computer and use it in GitHub Desktop.
Efficient POSIX way to get the last argument of a shell script.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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