help - Display information about shell builtin commands, 显示shell内置命令的帮助信息。
bash对每个shell内置命令都提供了帮助功能,使用help命令,将shell内置命令作为参数,就可以显示此shell内置命令的帮助信息。
在shell内置命令执行时,加上“--help”选项,也可以显示帮助信息。这两种方式都可以。
另外,许多可执行程序也支持"--help "选项,显示该命令支持的语法和选项的描述。
关于帮助信息的说明:
在中括号[]里的参数是可选参数,而竖线“|”则表示互斥的选项,只能从中选一个。
语法:
help [-dms] [pattern ...]
参数:
PATTERN - 指定一个要显示帮助信息的主题
返回值:
成功返回0;如果PATTERN没找到或参数不正确,返回失败。
常用选项
|
Option |
Long Option |
Meaning |
|
-d |
输出一个简单的功能说明。 | |
|
-m |
模范manpage的格式显示帮助信息。 | |
|
-s |
仅显示一个简短的语法使用格式说明。 |
示例
$ help -d help
help - Display information about builtin commands.
$ help -s help
help: help [-dms] [pattern ...]
$ help -m help
NAME
help - Display information about builtin commands.
SYNOPSIS
help [-dms] [pattern ...]
DESCRIPTION
Display information about builtin commands.
Displays brief summaries of builtin commands. If PATTERN is
specified, gives detailed help on all commands matching PATTERN,
otherwise the list of help topics is printed.
Options:
-d output short description for each topic
-m display usage in pseudo-manpage format
-s output only a short usage synopsis for each topic matching
PATTERN
Arguments:
PATTERN Pattern specifying a help topic
Exit Status:
Returns success unless PATTERN is not found or an invalid option is given.
SEE ALSO
bash(1)
IMPLEMENTATION
GNU bash, version 5.0.17(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
$ help --help
help: help [-dms] [pattern ...]
Display information about builtin commands.
Displays brief summaries of builtin commands. If PATTERN is
specified, gives detailed help on all commands matching PATTERN,
otherwise the list of help topics is printed.
Options:
-d output short description for each topic
-m display usage in pseudo-manpage format
-s output only a short usage synopsis for each topic matching
PATTERN
Arguments:
PATTERN Pattern specifying a help topic
Exit Status:
Returns success unless PATTERN is not found or an invalid option is given.
如果不加参数,则显示所有的help命令所支持的帮助主题:

Shell命令帮助:使用help和--help选项获取信息
本文介绍了如何在bash shell中使用`help`命令和`--help`选项来获取内置命令和可执行程序的帮助信息。`help`命令可以显示简洁的命令概要,加上`-d`、`-m`或`-s`选项可分别获取简短描述、模拟manpage格式或简短使用格式的信息。不提供参数时,`help`会列出所有可用的帮助主题。此外,很多程序也支持`--help`选项以显示命令的语法和选项。
8751

被折叠的 条评论
为什么被折叠?



