Reserved words
Some words have special meaning in shell syntax. These reserved words must be quoted to use them literally. The reserved words are:
!– Negation{– Start of a grouping}– End of a grouping[[– Start of a double bracket commandcase– Case commanddo– Start of a loop or conditional blockdone– End of a loop or conditional blockelif– Else if clauseelse– Else clauseesac– End of a case commandfi– End of an if commandfor– For loopfunction– Function definitionif– If commandin– Delimiter for a for loop and case commandthen– Then clauseuntil– Until loopwhile– While loop
Currently, [[ and function are only recognized as reserved words; their functionality is not yet implemented.
Additionally, the POSIX standard allows for the following optional reserved words:
]]– End of a double bracket commandnamespace– Namespace declarationselect– Select commandtime– Time command- Any words that end with a colon (
:)
These words are not reserved in yash-rs now, but may be in the future.
Where are reserved words recognized?
Reserved words are recognized in these contexts:
- As the first word of a command
- As a word following any reserved word other than
case,for, orin inas the third word in a for loop or case commanddoas the third word in a for loop
Examples
This example uses the reserved words for, in, do, and done in a for loop:
$ for i in 1 2 3; do echo $i; done
1
2
3
In the following example, {, do, and } are not reserved words because they are not the first word of the command:
$ echo { do re mi }
{ do re mi }
Reserved words are recognized only when they appear as a whole word. In this example, { and } are not reserved words because they are part of {echo and Hello}:
$ {echo Hello}
error: cannot execute external utility "{echo"
--> <stdin>:1:1
|
1 | {echo Hello}
| ^^^^^ utility "{echo" not found
To use { and } as reserved words, write them as separate words:
$ { echo Hello; }
Hello