列出所有Bash Shell内置命令的方法示例
程序员文章站
2022-08-31 18:11:05
前言
shell有很多内置在其源代码中的命令。这些命令是内置的,所以shell不必到磁盘上搜索它们,执行速度因此加快。不同的shell内置命令有所不同。
内置命令包含在...
前言
shell有很多内置在其源代码中的命令。这些命令是内置的,所以shell不必到磁盘上搜索它们,执行速度因此加快。不同的shell内置命令有所不同。
内置命令包含在 bash shell 本身里面。我该如何在 linux / apple os x / *bsd / unix 类操作系统列出所有的内置 bash 命令,而不用去读大篇的 bash 操作说明页?
shell 内置命令就是一个命令或一个函数,从 shell 中调用,它直接在 shell 中执行。 bash shell 直接执行该命令而无需调用其他程序。你可以使用 help 命令查看 bash 内置命令的信息。以下是几种不同类型的内置命令。
内置命令的类型
- bourne shell 内置命令:内置命令继承自 bourne shell。
- bash 内置命令:特定于 bash 的内置命令表。
- 修改 shell 行为:修改 shell 属性和可选行为的内置命令。
- 特别的内置命令:由 posix 特别分类的内置命令。
如何查看所有 bash 内置命令
有以下的命令:
$ help $ help | less $ help | grep read
样例输出:
gnu bash, version 4.1.5(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 hist> (( expression )) if commands; then commands; [ elif c> . filename [arguments] jobs [-lnprs] [jobspec ...] or jobs > : kill [-s sigspec | -n signum | -sigs> [ arg... ] let arg [arg ...] [[ expression ]] local [option] name[=value] ... alias [-p] [name[=value] ... ] logout [n] bg [job_spec ...] mapfile [-n count] [-o origin] [-s c> bind [-lpvspvs] [-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] [-> cd [-l|-p] [dir] readarray [-n count] [-o origin] [-s> command [-pvv] command [arg ...] readonly [-af] [name[=value] ...] or> compgen [-abcdefgjksuv] [-o option] > return [n] complete [-abcdefgjksuv] [-pr] [-de] > select name [in words ... ;] do comm> compopt [-o|+o option] [-de] [name ..> set [--abefhkmnptuvxbchp] [-o option> continue [n] shift [n] coproc [name] command [redirections] shopt [-pqsu] [-o] [optname ...] declare [-aaffilrtux] [-p] [name[=val> source filename [arguments] dirs [-clpv] [+n] [-n] suspend [-f] disown [-h] [-ar] [jobspec ...] test [expr] echo [-nee] [arg ...] time [-p] pipeline enable [-a] [-dnps] [-f filename] [na> times eval [arg ...] trap [-lp] [[arg] signal_spec ...] exec [-cl] [-a name] [command [argume> true exit [n] type [-afptp] name [name ...] export [-fn] [name[=value] ...] or ex> typeset [-aaffilrtux] [-p] name[=val> false ulimit [-shacdefilmnpqrstuvx] [limit> fc [-e ename] [-lnr] [first] [last] o> umask [-p] [-s] [mode] fg [job_spec] unalias [-a] name [name ...] for name [in words ... ] ; do command> unset [-f] [-v] [name ...] for (( exp1; exp2; exp3 )); do comman> until commands; do commands; done function name { commands ; } or name > variables - names and meanings of so> getopts optstring name [arg] wait [id] hash [-lr] [-p pathname] [-dt] [name > while commands; do commands; done help [-dms] [pattern ...] { commands ; }
另外一种选择是使用下列命令:
compgen -b compgen -b | more
查看 bash 的内置命令信息
运行以下得到详细信息:
help command help read
要仅得到所有带简短描述的内置命令的列表,执行如下:
$ help -d
查找内置命令的语法和其他选项
使用下列语法去找出更多的相关内置命令:
help name help cd help fg help for help read help :
样例输出:
:: : null command. no effect; the command does nothing. exit status: always succeeds
找出一个命令是内部的(内置)还是外部的
使用 type 命令或 command 命令:
type -a command-name-here type -a cd type -a uname type -a : type -a ls
或者:
type -a cd uname : ls uname
样例输出:
cd is a shell builtin uname is /bin/uname : is a shell builtin ls is aliased to `ls --color=auto' ls is /bin/ls l is a function l () { ls --color=auto }
或者:
command -v ls command -v cd command -v foo
view list bash built-ins command info on linux or unix
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对的支持。
下一篇: 全自动咖啡机和半自动咖啡机的区别有哪些