如何列出所有可用的shell内置命令?

我们知道bash支持的buitin命令数量如下:

$ type type cd help command type is a shell builtin cd is a shell builtin help is a shell builtin command is a shell builtin 

我想获得所有可用的shell内置命令的列表 。 我如何通过命令行执行此操作?

从终端类型:

 help 

来自help help

 Display information about builtin commands. 

您可以使用bash shell中的compgen -b来获取shell的内置命令列表。

或者你可以使用enable命令显示:(两个@ karel和@ steeldriver的答案都可以。)

 enable -a | cut -d " " -f 2,3 

如果任何内置函数被禁用,则在输出中显示为-n

输出示例:

 $ enable -a | cut -d " " -f 2,3 . : [ alias bg bind break builtin caller cd command compgen complete compopt continue declare dirs disown echo enable eval exec exit export false fc fg getopts hash help history jobs kill let local logout mapfile popd printf pushd pwd read readarray readonly return set shift shopt source suspend test times trap true type typeset ulimit umask unalias unset wait 

只需输入终端:

 man bash 

这将打开bash手册。 向下滚动你会发现SHELL BUILTIN COMMANDS 。 在这里,您可以了解所有内置命令及其function。 如果您希望手册采用txt格式,请使用此命令

 man bash > FILENAME.txt 

现在你有了bash手册的文本文件。

对于那些讨厌分析外部二进制文件而仅仅是为了数据格式化/提取的人:

 while read -r _ cmd ; do echo $cmd ; done < <(enable -a)