如何列出所有shell关键字?

$ type if if is a shell keyword 

我不知道其他shell关键字。

是否有任何命令列出所有bash shell关键字。?

注意: help -m显示shell内置和shell关键字。

为此,存在一个名为compgen shell内置命令,当你运行help -m时,你肯定没有注意到它。

 $ compgen -k if then else elif fi case esac for select while until do done in function time { } ! [[ ]] coproc 

有关help -m compgen的更多信息,请参阅help -m compgen compgen

从这里采取的想法:

  • 在bash中,要列出所有关键字,首先在终端中运行以下命令:

     complete -A keyword : 
  • 然后在提示符处输入:: Space Tab Tab

对我来说效果很好:

 ! { coproc elif fi if then while [[ } do else for in time ]] case done esac function select until