如何列出所有shell关键字?

Avi*_*Raj 17 command-line bash

$ type if
if is a shell keyword
Run Code Online (Sandbox Code Playgroud)

我不知道其他 shell 关键字。

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

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

Rad*_*anu 15

为此存在调用的 shell 内置命令compgen,您在运行时肯定没有注意到它help -m

$ compgen -k
if
then
else
elif
fi
case
esac
for
select
while
until
do
done
in
function
time
{
}
!
[[
]]
coproc
Run Code Online (Sandbox Code Playgroud)

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


Spa*_*awk 5

这里采取的想法:

对我来说效果很好:

!         {         coproc    elif      fi        if        then      while     
[[        }         do        else      for       in        time      
]]        case      done      esac      function  select    until     
Run Code Online (Sandbox Code Playgroud)