Skip to content

Instantly share code, notes, and snippets.

@gonsie
Forked from kylelemons/scripttemplate.sh
Created June 25, 2012 17:29
Show Gist options
  • Select an option

  • Save gonsie/2990033 to your computer and use it in GitHub Desktop.

Select an option

Save gonsie/2990033 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>
###
# Quick usage printout
if [ $# -eq 0 ]; then
echo "Usage: `basename $0` flag option"
exit 65
fi
# 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