19
$ type if
if is a shell keyword

I don't know the other shell keywords.

Is there any command to list all the bash shell keywords.?

Note: help -m displays both shell builtins and shell keywords.

Eliah Kagan
  • 116,445
  • 54
  • 318
  • 493
Avinash Raj
  • 77,204
  • 56
  • 214
  • 254
  • I am glad to share these two links which are related and helpful: visit [this](http://unix.stackexchange.com/q/151118/66803) & [this](http://stackoverflow.com/q/948008) – Pandya Aug 20 '14 at 11:12
  • Related (for builtins instead of keywords): [How do I list all available shell builtin commands?](https://askubuntu.com/questions/512918/how-do-i-list-all-available-shell-builtin-commands) – Eliah Kagan Sep 05 '19 at 00:13

2 Answers2

17

For this exists that shell builtin command called compgen which most certainly you did not notice it when you run help -m.

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

See help -m compgen for more info about compgen.

Radu Rădeanu
  • 166,822
  • 48
  • 327
  • 400
5

Idea taken from here:

  • In bash, to list all keywords, first run the following command in terminal:

    complete -A keyword :
    
  • Then type at the prompter: :SpaceTabTab.

Works very well for me:

!         {         coproc    elif      fi        if        then      while     
[[        }         do        else      for       in        time      
]]        case      done      esac      function  select    until     
Sparhawk
  • 6,872
  • 7
  • 48
  • 78