Differences between keyword, reserved word, and builtin?
Keyword, reserved word, and builtin are all the "first word" of a Simple command. Could be placed in two groups: Keyword and Builtin. The two are mutually exclusive. A word (token) can be either a Keyword or a builtin, but not both.
Why the "first word"
From the POSIX definition of "Simple command"(emphasis mine):
A "simple command" is a sequence of optional variable assignments and redirections, in any sequence, optionally followed by words and redirections, terminated by a control operator.
2.- The words that are not variable assignments or redirections shall be expanded. If any fields remain following their expansion, the first field shall be considered the command name and remaining fields are the arguments for the command.
After that "first word" has been identified, and after is has been expanded (by an alias, for example) the final word is "the command", there could be only one command in each line. That command word could be a Built-in or a keyword.
Keyword
Yes, a keyword is a "reserved word". Load "man bash" and search for keyword. (or just execute this command: LESS=+/'keyword' man bash
.
The first hit on search say this:
keyword Shell reserved words.
It happens in the completion section, but is quite clear.
Reserved Words
In POSIX, there is this definition of "Reserved Words" and some description of what Reserved Words do.
But the bash manual has a better working definition.
Search for "RESERVED WORDS" (LESS=+/'RESERVED WORDS' man bash
) and find this:
RESERVED WORDS Reserved words are words that have a special meaning to the shell.
The following words are recognized as reserved when unquoted and either the first word of a simple command or the third word of a case or for command:! case do done elif else esac fi for function if in select then until while { } time [[ ]]
Builtin
It is not defined in the bash manual, but it is quite simple:
It is a command that has been implemented inside the shell for UN-avoidable needs of the shell (cd, pwd, eval), or speed in general or to avoid conflicting interpretations of external utilities in some cases.
Time is a keyword.
why is time not a builtin but a keyword?
To allow the existence of a command as the second word.
It is similar as how an if ... then .... fi
allow the inclusion of commands (even compound commands) after the first key-word if
. Or while
or case
, etc.