Skip to content

Instantly share code, notes, and snippets.

@kenbarbour
Last active July 30, 2018 03:16
Show Gist options
  • Save kenbarbour/99ec639bf08d932793e4d04cde3149df to your computer and use it in GitHub Desktop.
Save kenbarbour/99ec639bf08d932793e4d04cde3149df to your computer and use it in GitHub Desktop.
A basic skeleton bash script with a usage statement
#!/bin/bash
##
## Skeleton Script that does nothing useful. This is the script that I copy
## when I make other scripts.
##
## Usage: _PROG_ [OPTIONS]
##
## Options:
## -h --help Display help message and exit
##
prog="$0"
me=`basename "$prog"`
dohelp(){
grep '^##' "$prog" | sed -e 's/^##\s\?//' -e "s/_PROG_/$me/" 1>&2
exit
}
if [ "$1" = "-h" -o "$1" = "--help" ] ; then
dohelp
fi
# Do the script
@kenbarbour
Copy link
Author

For some more details on this method of self-documenting bash scripts, see this article from Linux Daily: http://www.thelinuxdaily.com/2012/09/self-documenting-scripts/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment