Last active
August 29, 2015 14:25
-
-
Save mralexgray/bb67d31aafd4f3217c1f to your computer and use it in GitHub Desktop.
Canonical shell argument parsing.
This file contains 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
#!/usr/bin/env zsh | |
# Print usage information if there are no arguments on the command line. | |
[ "$#" = "0" ] && | |
echo 'Usage: via-ssh.sh [ -v ] [ -d ] [USER@]SERVER[:PORT]' && exit 1 | |
# Process the command line parameters. | |
while [ "$#" != '0' ] ; do | |
case "$1" in | |
-v) VERBOSE=1 ; shift ;; | |
-d) DNS=1 ; shift ;; | |
*) SSH_PORT=${1##*:} | |
SSH_USER_SERVER=${1%%:*} | |
[ "$SSH_USER_SERVER" = "$SSH_PORT" ] && SSH_PORT=22 | |
shift ;; | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment