如何列出所有的shell关键字?


15
$ type if
if is a shell keyword

我不知道其他shell关键字。

有没有列出所有bash shell关键字的命令?

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


我很高兴地分享这两个环节这是相关的,有用的:参观
潘迪亚

相关(对于内建而不是关键字):如何列出所有可用的Shell内建命令?
伊莱亚·卡根

Answers:


12

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

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

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


3

想法来自这里

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

    complete -A keyword :
  • 然后在提示下输入::SpaceTabTab

对我来说效果很好:

!         {         coproc    elif      fi        if        then      while     
[[        }         do        else      for       in        time      
]]        case      done      esac      function  select    until     
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.