Words, tokens and shell operators
How it works
Before Bash runs a command, it reads its source text and recognizes words and operators. A token is a unit recognized by the parser. Unquoted spaces and tabs separate words; an unquoted semicolon separates commands. Quoting changes how characters are interpreted. The shell later expands words into arguments, so a source word and a final argument are not always the same thing. Reserved words such as if have special meaning only in appropriate grammatical positions; conditions are taught later.
Run each example separately in a fresh noninteractive Bash script with default options. Tested on Bash 5.2.37 with C locale. Do not enter the prompt or the expected output as code.
One word or two?
Expected stdout (tabs are real characters):
[red][blue][red blue]The first command has two data arguments; the second has one. The brackets are part of the format, not part of the arguments.
Semicolon as syntax or data
printf '%s\n' Start; printf '%s\n' Endprintf '%s\n' 'Start; End'Expected stdout (tabs are real characters):
StartEndStart; EndThe unquoted semicolon separates commands even without a surrounding space. Inside quotes it is ordinary text.
When a hash starts a comment
Expected stdout (tabs are real characters):
item#7#7In a normal noninteractive script, an unquoted # at the beginning of a word starts a comment; embedded or quoted # stays literal.
Common mistakes
Do not assume every punctuation mark is an operator wherever it appears. printf with a quoted semicolon prints data; a semicolon outside quotes is syntax. Operators such as | and > are introduced in later chapters.
Practice
Print the literal line status; ready #1 as a single data argument, then print done using a second command on the same source line.
Next: Single and double quotes