获取有关 Linux shell 内置命令的帮助


获取有关 Linux shell 内置命令的帮助

文章插图
 
linux 内置命令属于用户 shell 的一部分,本文将告诉你如何识别它们并获取使用它们的帮助 。
-- Sandra Henry-stocker(作者)
Linux 内置命令是内置于 shell 中的命令,很像内置于墙中的书架 。与标准 Linux 命令存储在 /usr/bin 中的方式不同,你不会找到它们的独立文件,你可能使用过相当多的内置命令,但你不会感觉到它们与 ls 和 pwd 等命令有何不同 。
内置命令与其他 Linux 命令一样使用,它们可能要比不属于 shell 的类似命令运行得快一些 。Bash 内置命令包括 alias、export 和 bg 等 。
正如你担心的那样,因为内置命令是特定于 shell 的,所以它们不会提供手册页 。使用 man 来查看 bg,你会看到这样的东西:
【获取有关 Linux shell 内置命令的帮助】$ man bgNo manual entry for bg判断内置命令的另一个提示是当你使用 which 命令来识别命令的来源时,Bash 不会响应,表示没有与内置命令关联的文件:
$ which bg$另一方面,如果你的 shell 是 /bin/zsh,你可能会得到一个更有启发性的响应:
% which bgbg: shell built-in commandbash 提供了额外的帮助信息,但它是通过使用 help 命令实现的:
$ help bgbg: bg [job_spec ...] Move jobs to the background. Place the jobs identified by each JOB_SPEC in the background, as if they had been started with `&'. If JOB_SPEC is not present, the shell's notion of the current job is used. Exit Status: Returns success unless job control is not enabled or an error occurs.如果你想要查看 bash 提供的所有内置命令的列表,使用 compgen -b 命令 。通过管道将命令输出到列中,以获得较好格式的清单 。
$ compgen -b | column. compgen exit let return typeset: complete export local set ulimit[ compopt false logout shift umaskalias continue fc mapfile shopt unaliasbg declare fg popd source unsetbind dirs getopts printf suspend waitbreak disown hash pushd testbuiltin echo help pwd timescaller enable history read trapcd eval jobs readarray truecommand exec kill readonly type如果你使用 help 命令,你将看到一个内置命令列表以及简短描述 。但是,这个列表被截断了(以 help 命令结尾):
$ helpGNU bash, version 5.0.3(1)-release (x86_64-pc-linux-gnu)These shell commands are defined internally. Type `help' to see this list.Type `help name' to find out more about the function `name'.Use `info bash' to find out more about the shell in general.Use `man -k' or `info' to find out more about commands not in this list.A star (*) next to a name means that the command is disabled. job_spec [&] history [-c] [-d offset] [n] or histo> (( expression )) if COMMANDS; then COMMANDS; [ elif CO> . filename [arguments] jobs [-lnprs] [jobspec ...] or jobs -> : kill [-s sigspec | -n signum | -sigsp> [ arg... ] let arg [arg ...] [[ expression ]] local [option] name[=value] ... alias [-p] [name[=value] ... ] logout [n] bg [job_spec ...] mapfile [-d delim] [-n count] [-O ori> bind [-lpsvPSVX] [-m keymap] [-f filen> popd [-n] [+N | -N] break [n] printf [-v var] format [arguments] builtin [shell-builtin [arg ...]] pushd [-n] [+N | -N | dir] caller [expr] pwd [-LP] case word in [PATTERN [| PATTERN]...) > read [-ers] [-a array] [-d delim] [-i> cd [-L|[-P [-e]] [-@]] [dir] readarray [-d delim] [-n count] [-O o> command [-pVv] command [arg ...] readonly [-aAf] [name[=value] ...] or> compgen [-abcdefgjksuv] [-o option] [-> return [n] complete [-abcdefgjksuv] [-pr] [-DEI] > select NAME [in WORDS ... ;] do COMMA> compopt [-o|+o option] [-DEI] [name ..> set [-abefhkmnptuvxBCHP] [-o option-n> continue [n] shift [n] coproc [NAME] command [redirections] shopt [-pqsu] [-o] [optname ...] declare [-aAfFgilnrtux] [-p] [name[=va> source filename [arguments] dirs [-clpv] [+N] [-N] suspend [-f] disown [-h] [-ar] [jobspec ... | pid . <p&gt'> test [expr] echo [-neE] [arg ...] time [-p] pipeline enable [-a] [-dnps] [-f filename] [nam> times eval [arg ...] trap [-lp] [[arg] signal_spec ...] exec [-cl] [-a name] [command [argumen> true exit [n] type [-afptP] name [name ...] export [-fn] [name[=value] ...] or exp> typeset [-aAfFgilnrtux] [-p] name[=va> false ulimit [-SHabcdefiklmnpqrstuvxPT] [li> fc [-e ename] [-lnr] [first] [last] or> umask [-p] [-S] [mode] fg [job_spec] unalias [-a] name [name ...] for NAME [in WORDS ... ] ; do COMMANDS> unset [-f] [-v] [-n] [name ...] for (( exp1; exp2; exp3 )); do COMMAND> until COMMANDS; do COMMANDS; done function name { COMMANDS ; } or name (> variables - Names and meanings of som> getopts optstring name [arg] wait [-fn] [id ...] hash [-lr] [-p pathname] [-dt] [name .> while COMMANDS; do COMMANDS; done help [-dms] [pattern ...] { COMMANDS ; }


推荐阅读