Created
March 17, 2019 06:33
-
-
Save thealanberman/7534842d0d1388211b2c0f7e505cf240 to your computer and use it in GitHub Desktop.
Self documenting Bash script
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
#!/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