Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Self documenting Bash script
#!/usr/bin/env bash
if [[ ${*} =~ help|-h || ${#} == 0 ]]; then cat <<HELP_USAGE | sed "s/^#? //"
#? USAGE
#? ======
#? Anywhere in your script:
#?
#? if [[ $* =~ help|-h || $# == 0 ]]; then cat <<HELP_USAGE | sed "s/^#? //"
#? #? Documentation lines prefixed with '#? '
#? HELP_USAGE
#? exit 0; fi
#?
#? FEATURES
#? ========
#? * Preformatted.
#? * Variable expansion: \${HOME} is '${HOME}'
#? * Commands can be executed
#? '\$(echo Foo)' results in '$(echo Foo)'
#? * Script being documented can self referenced
#? '\${0}' => '${0}'
#?
HELP_USAGE
exit 0; fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment