如何列出所有的Bash Shell内置命令

系统 Linux
shell 内置命令就是一个命令或一个函数,从 shell 中调用,它直接在 shell 中执行。 bash shell 直接执行该命令而无需调用其他程序。你可以使用 help 命令查看 Bash 内置命令的信息。以下是几种不同类型的内置命令。

[[220455]]

内置命令包含在 bash shell 本身里面。我该如何在 Linux / Apple OS X / *BSD / Unix 类操作系统列出所有的内置 bash 命令,而不用去读大篇的 bash 操作说明页?

shell 内置命令就是一个命令或一个函数,从 shell 中调用,它直接在 shell 中执行。 bash shell 直接执行该命令而无需调用其他程序。你可以使用 help 命令查看 Bash 内置命令的信息。以下是几种不同类型的内置命令。

 

内置命令的类型

  1. Bourne Shell 内置命令:内置命令继承自 Bourne Shell。
  2. Bash 内置命令:特定于 Bash 的内置命令表。
  3. 修改 Shell 行为:修改 shell 属性和可选行为的内置命令。
  4. 特别的内置命令:由 POSIX 特别分类的内置命令。

 

如何查看所有 bash 内置命令

有以下的命令:

  1. $ help
  2. $ help | less
  3. $ help | grep read

样例输出:

  1. GNU bash, version 4.1.5(1)-release (x86_64-pc-linux-gnu)
  2. These shell commands are defined internally. Type `help' to see this list.
  3. Type `help name' to find out more about the function `name'.
  4. Use `info bash' to find out more about the shell in general.
  5. Use `man -k' or `info' to find out more about commands not in this list.
  6.  
  7. A star (*) next to a name means that the command is disabled.
  8.  
  9. job_spec [&] history [-c] [-d offset] [n] or hist>
  10. (( expression )) if COMMANDS; then COMMANDS; [ elif C>
  11. . filename [arguments] jobs [-lnprs] [jobspec ...] or jobs >
  12. : kill [-s sigspec | -n signum | -sigs>
  13. [ arg... ] let arg [arg ...]
  14. [[ expression ]] local [option] name[=value] ...
  15. alias [-p] [name[=value] ... ] logout [n]
  16. bg [job_spec ...] mapfile [-n count] [-O origin] [-s c>
  17. bind [-lpvsPVS] [-m keymap] [-f filen> popd [-n] [+N | -N]
  18. break [n] printf [-v var] format [arguments]
  19. builtin [shell-builtin [arg ...]] pushd [-n] [+N | -N | dir]
  20. caller [expr] pwd [-LP]
  21. case WORD in [PATTERN [| PATTERN]...)> read [-ers] [-a array] [-d delim] [->
  22. cd [-L|-P] [dir] readarray [-n count] [-O origin] [-s>
  23. command [-pVv] command [arg ...] readonly [-af] [name[=value] ...] or>
  24. compgen [-abcdefgjksuv] [-o option] > return [n]
  25. complete [-abcdefgjksuv] [-pr] [-DE] > select NAME [in WORDS ... ;] do COMM>
  26. compopt [-o|+o option] [-DE] [name ..> set [--abefhkmnptuvxBCHP] [-o option>
  27. continue [n] shift [n]
  28. coproc [NAME] command [redirections] shopt [-pqsu] [-o] [optname ...]
  29. declare [-aAfFilrtux] [-p] [name[=val> source filename [arguments]
  30. dirs [-clpv] [+N] [-N] suspend [-f]
  31. disown [-h] [-ar] [jobspec ...] test [expr]
  32. echo [-neE] [arg ...] time [-p] pipeline
  33. enable [-a] [-dnps] [-f filename] [na> times
  34. eval [arg ...] trap [-lp] [[arg] signal_spec ...]
  35. exec [-cl] [-a name] [command [argume> true
  36. exit [n] type [-afptP] name [name ...]
  37. export [-fn] [name[=value] ...] or ex> typeset [-aAfFilrtux] [-p] name[=val>
  38. false ulimit [-SHacdefilmnpqrstuvx] [limit>
  39. fc [-e ename] [-lnr] [first] [last] o> umask [-p] [-S] [mode]
  40. fg [job_spec] unalias [-a] name [name ...]
  41. for NAME [in WORDS ... ] ; do COMMAND> unset [-f] [-v] [name ...]
  42. for (( exp1; exp2; exp3 )); do COMMAN> until COMMANDS; do COMMANDS; done
  43. function name { COMMANDS ; } or name > variables - Names and meanings of so>
  44. getopts optstring name [arg] wait [id]
  45. hash [-lr] [-p pathname] [-dt] [name > while COMMANDS; do COMMANDS; done
  46. help [-dms] [pattern ...] { COMMANDS ; }

另外一种选择是使用下列命令:

  1. compgen -b
  2. compgen -b | more

 

查看 Bash 的内置命令信息

运行以下得到详细信息:

  1. help command
  2. help read

要仅得到所有带简短描述的内置命令的列表,执行如下:

  1. $ help -d

 

查找内置命令的语法和其他选项

使用下列语法去找出更多的相关内置命令:

  1. help name
  2. help cd
  3. help fg
  4. help for
  5. help read
  6. help :

样例输出:

  1. :: :
  2. Null command.
  3.  
  4. No effect; the command does nothing.
  5.  
  6. Exit Status:
  7. Always succeeds

 

找出一个命令是内部的(内置)还是外部的

使用 type 命令或 command 命令:

  1. type -a command-name-here
  2. type -a cd
  3. type -a uname
  4. type -a :
  5. type -a ls

或者:

  1. type -a cd uname : ls uname

样例输出:

  1. cd is a shell builtin
  2. uname is /bin/uname
  3. : is a shell builtin
  4. ls is aliased to `ls --color=auto'
  5. ls is /bin/ls
  6. l is a function
  7. l ()
  8. {
  9. ls --color=auto
  10. }
  11.  

或者:

  1. command -V ls
  2. command -V cd
  3. command -V foo

View list bash built-ins command info on Linux or Unix

View list bash built-ins command info on Linux or Unix 

责任编辑:庞桂玉 来源: Linux中国
相关推荐

2010-04-07 17:55:12

Unix命令

2010-06-23 17:34:03

Linux Bash

2010-06-23 17:37:14

Linux Bash

2010-06-23 14:45:02

Linux Bash

2010-06-23 17:16:33

Linux Bash

2010-06-23 17:29:07

Linux Bash

2010-06-23 16:31:10

Linux Bash

2021-08-30 07:50:42

脚本语言命令行

2009-12-25 09:47:05

LinuxShell编程bash

2019-07-29 15:36:15

Linuxshell内置命令

2020-06-24 15:30:39

Bashhistory命令Linux

2010-06-23 16:09:40

Linux Bash

2010-06-23 16:35:50

Linux Bash

2009-07-16 10:58:11

C#枚举

2013-12-20 10:20:34

2017-07-10 17:00:24

程序语言语言特性

2018-02-01 17:32:30

LinuxUNIXBash Shell

2022-05-02 18:29:35

bashshellLinux

2010-07-14 17:37:33

SQL Server

2022-11-23 08:14:42

bash 脚本test 命令
点赞
收藏

51CTO技术栈公众号