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.

2

2 Answers 2

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.

1
  • time and coproc are implemented as keywords but they feel more like regular commands when you're writing Bash.
    – user677955
    Apr 16, 2023 at 11:44
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     
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .