Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
help text for bas script based on ### comment + awk command
#!/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
@ivanistheone
Copy link
Author

ivanistheone commented Jul 7, 2020

Credit @kovetskiy for original idea, @benhutchins for making it cross-platform using awk, and @jdugan1024 for improvements in awk command.

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