Shell Script Interfaces
Usage Line
Explain the Interface
A usage line tells callers which command form the script accepts. It should match the names and options the script actually parses.
Program
Play the script to choose a command name and see the generated usage text.
usage_line.sh
Replay: real traced execution (multi-file project)
#!/usr/bin/env bash
script_name="deploy.sh"
usage="usage: $script_name [--dry-run] <target>"
echo "$usage"
#!/usr/bin/env bash
script_name="backup.sh"
usage="usage: $script_name [--dry-run] <target>"
echo "$usage"
script_name ← deploy.sh
3script_name="deploy.sh"4usage="usage: $script_name [--dry-run] <target>"values this stepdeploy.shscript_nameusage ← usage: deploy.sh [--dry-run] <target>
3script_name="deploy.sh"4usage="usage: $script_name [--dry-run] <target>"5echo "$usage"values this stepusage: deploy.sh [--dry-run] <target>usagedeploy.shscript_nameecho "$usage"
4usage="usage: $script_name [--dry-run] <target>"5echo "$usage"outputusage: deploy.sh [--dry-run] <target>values this stepusage: deploy.sh [--dry-run] <target>usage
script_name ← backup.sh
3script_name="backup.sh"4usage="usage: $script_name [--dry-run] <target>"values this stepbackup.shscript_nameusage ← usage: backup.sh [--dry-run] <target>
3script_name="backup.sh"4usage="usage: $script_name [--dry-run] <target>"5echo "$usage"values this stepusage: backup.sh [--dry-run] <target>usagebackup.shscript_nameecho "$usage"
4usage="usage: $script_name [--dry-run] <target>"5echo "$usage"outputusage: backup.sh [--dry-run] <target>values this stepusage: backup.sh [--dry-run] <target>usage
usage
Usage text is the short contract shown when a caller needs help.
script name
Using the script name variable keeps help text reusable.
argument contract
`<target>` signals a required positional argument.