Skip to content

Instantly share code, notes, and snippets.

@kylelemons
Created July 19, 2011 22:52
Show Gist options
  • Save kylelemons/1093946 to your computer and use it in GitHub Desktop.
Save kylelemons/1093946 to your computer and use it in GitHub Desktop.
BASH Script template
###
### 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