LinuxCommandLibrary

help

Display command usage information

TLDR

Display the full list of builtin commands

$ help
copy

Print instructions on how to use the while loop construct
$ help while
copy

Print instructions on how to use the for loop construct
$ help for
copy

Print instructions on how to use [[ ]] for conditional commands
$ help [[
copy

Print instruction on how to use (( )) to evaluate arithmetic expressions
$ help \(
copy

Print instructions on how to use the cd command
$ help cd
copy

SYNOPSIS

help [-dEhmqs] [-o opt] [pattern ...]

PARAMETERS

-d
    print a short description, or usage synopsis for some builtins

-E
    classify functions into basic/reserved/special

-h
    display help for help itself and exit

-m
    display help in pseudo-manpage format

-o opt
    set output format (e.g., json, xml, vim)

-q
    quiet mode; suppress output if no match found

-s
    print only a short usage synopsis, like --help

DESCRIPTION

The help command is a Bash shell built-in utility designed to provide concise documentation and usage information specifically for other Bash built-in commands. Bash builtins, such as cd, echo, and read, lack traditional man pages, making help the primary source for their syntax, options, and behavior.

Invoked without arguments, help lists all available built-ins in a formatted table. Specifying a command name, like help cd, outputs detailed help for that builtin. It supports shell glob patterns (e.g., help cd *) to match and display help for multiple commands.

Various options control output format: short synopses for quick reference, manpage-style for readability, or even structured formats like JSON. This makes help invaluable for interactive shell use, scripting, and learning Bash internals. It extracts information directly from Bash's internal documentation strings, ensuring accuracy tied to the current shell version.

Primarily useful in Bash environments, help enhances productivity by keeping documentation accessible without external tools, though it does not cover POSIX builtins or external utilities.

CAVEATS

Only works for Bash built-ins, not external commands or functions unless marked as such. Output depends on Bash version; unavailable in non-Bash shells like dash.

EXAMPLES

help # List all builtins
help cd # Help for cd
help -m read # Manpage-style for read
help -s *e* # Short help for matching builtins

NO MATCH BEHAVIOR

Exits with status 1 if no builtins match the pattern; use -q to suppress errors.

HISTORY

Introduced in Bash 2.0 (1996) to address lack of documentation for builtins. Enhanced in later versions: Bash 4.0 added -m; Bash 4.4 added -o formats; Bash 5.0 expanded options like -E and -q.

SEE ALSO

type(1), man(1), info(1), builtin(1)

Copied to clipboard