Created
July 19, 2011 22:52
-
-
Save kylelemons/1093946 to your computer and use it in GitHub Desktop.
BASH Script template
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
### | |
### Usage: blah [<options>] | |
### | |
### Description of the script | |
### | |
### Options: | |
### -f --flag | |
### Description of the flag | |
### -o --option <arg> | |
### Description of the option and argument | |
### Examples: | |
### blah | |
### blah --option <blah> | |
### | |
# Defaults | |
FLAG=0 | |
OPTION="" | |
# Command-line options | |
while /bin/true; do | |
CURRARG=$1 | |
case $CURRARG in | |
"--flag" | "-f") | |
FLAG=1 | |
;; | |
"--option" | "-o") | |
OPTION="$2" | |
shift | |
;; | |
"-"*) | |
echo "Error: Unrecognized option $CURRARG" | |
grep "^###" $0 | sed -e 's/^###//' | |
exit 1 | |
;; | |
*) | |
break | |
;; | |
esac | |
shift | |
done | |
# Main script body |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment