Bash

Self-Documenting Help Text

admin by @admin ADMIN
1d ago
May 31, 2026
Public
0 0 up · 0 down Sign in to vote
A pattern where comments in your script double as inline help. Grep your own file for a sentinel string and print it as the --help output.
Bash
Raw
#!/usr/bin/env bash
##? Usage: deploy.sh [options] <environment>
##?
##? Deploy the app to a target environment.
##?
##? Options:
##?   -d, --dry-run     show what would happen, don't actually deploy
##?   -v, --verbose     extra logging
##?   -h, --help        show this help

show_help() {
    grep '^##?' "$0" | sed 's/^##? \?//'
}

case "${1:-}" in
    -h|--help) show_help; exit 0 ;;
esac

# rest of script…
Tags

Save your own code snippets

Create a free account and build your private vault. Share publicly whenever you want.