This article may be confusing or unclear to readers. Please help clarify the article. There might be a discussion about this on the talk page. (April 2008) (Learn how and when to remove this template message)

In computer programming, a usage message or help message is a brief message displayed by a program that utilizes a command-line interface for execution. This message usually consists of the correct command line usage for the program and includes a list of the correct command-line arguments or options acceptable to said program.

Usage messages are utilized as a quick way for a program to inform the user of proper command syntax, and should not be substituted for proper error messages or for detailed documentation such as a man page.

Pattern

On Unix-like platforms, usage messages usually follow the same common pattern:

Examples

Here is an example based on the NetBSD source code style guide:

Usage: program [-aDde] [-f | -g] [-n number] [-b b_arg | -c c_arg] req1 req2 [opt1 [opt2]]

This would indicate that "program" should be called with:

Implementation

To print a usage statement in a shell script, one might write:

case "$arg" in
...
h) printf 'Usage: %s parameter1 parameter2 ...\n' "$(basename "$0")"
   exit 0
   ;;
...
esac

Anti-patterns

A usage statement is not an error message, but is often used as a lazy way to avoid printing a useful error message. A usage statement should only be printed when specifically requested by the user (via --help, or -h, or -?, or some similar flag or argument) and should be written to the standard output;[1][2] if the user has entered an incorrect command line, a properly written command line program will print a succinct error message that describes the exact error made by the user rather than printing the usage statement and requiring the user to figure out what the mistake was. If the user fails to pass the correct number of arguments, for example, a single line stating that an argument is missing is far more useful than several pages of output providing a general usage.

See also

References

  1. ^ "CS 11: How to write usage statements".
  2. ^ "Usage Statements (Common Desktop Environment: Internationalization Programmer's Guide)".