Last active
January 6, 2016 17:46
-
-
Save joariasl/a94dc3fdd86e78ed8899 to your computer and use it in GitHub Desktop.
Bash command line arguments parse
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
#!/bin/bash | |
showUsage() { | |
echo "Usage: | |
Usage instruction..." | |
} | |
if (( ${#@} == 0 )); then | |
showUsage | |
exit 1 | |
fi | |
while [ "$1" != "" ]; do | |
case $1 in | |
-f | --file ) | |
shift | |
filename=$1 | |
;; | |
-i | --interactive ) | |
interactive=1 | |
;; | |
-h | --help ) | |
showUsage | |
exit 0 | |
;; | |
* ) | |
showUsage | |
exit 1 | |
;; | |
esac | |
shift | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment