作者展示了一個技巧,將幫助信息寫在 Bash 腳本腳本的頭部,然后只要執行"腳本名 + help",就能輸出這段幫助信息
https://samizdat.dev/help-message-for-shell-scripts/
#!/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