Forked from kovetskiy/samizdat-shell-help.bash
Last active
December 17, 2020 22:23
-
-
Save ivanistheone/0454191800c9caad77a52e0e29c8f31f to your computer and use it in GitHub Desktop.
help text for bas script based on ### comment + awk command
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
#!/bin/bash | |
### | |
### my-script — does one thing well | |
### | |
### Usage: | |
### my-script <input> <output> | |
### | |
### Options: | |
### <input> Input file to read. | |
### <output> Output file to write. Use '-' for stdout. | |
### -h Show this message. | |
help() { | |
awk -F'### ' '/^###/ { print $2 }' "$0" | |
} | |
if [[ $# == 0 ]] || [[ "$1" == "-h" ]]; then | |
help | |
exit 1 | |
fi | |
echo Hello World |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Credit @kovetskiy for original idea, @benhutchins for making it cross-platform using awk, and @jdugan1024 for improvements in awk command.