usage message
A short line a script prints to standard error when it is called wrongly, showing how it should be run.
In more detail
By convention it starts with usage:, names the options and placeholders, and is followed by exit 2. Putting it in a usage function lets every error path share it.
Example
echo "usage: backup.sh [-v] -d DIR" >&2; exit 2Related terms
- usage placeholder — A capitalised word in a usage line or manual page, such as FILE or PATTERN, that stands for a value you supply.
- exit code — A number a process returns when it finishes: 0 means success, anything else means something went wrong.
- getopts — The builtin that parses short command-line options such as -v, -vq and -f value, one option per call, in a while loop.
- standard output and standard error — The two channels a program writes normal output (stdout) and error messages (stderr) to, plus stdin for input.
Taught in
- Exit Codes, And What Success Means — Bash Scripting & Command Line Automation
- Arguments: Dollar One, Dollar At, shift — Bash Scripting & Command Line Automation
- Option Parsing With getopts — Bash Scripting & Command Line Automation