Bash (Unix shell): Difference between revisions

Content deleted Content added
m Unix shells: use columns
Syntax: prose, add double quotes
Line 503:
-->
: <syntaxhighlight lang = text>
"Tokens"
\_ "Blanks"
\_ "Operators" (Ops)
\_ "Control Ops"
\_ "Redirection Ops"
\_ "Words"
\_ "Reserved Words"
\_ "Names"
</syntaxhighlight>
 
When Bash reads a full commandline, the complete string is broken down according to a certain set of rules into individual units called ''"tokens."''
''"Tokens''" are identified using, and separated from each other using ''"metacharacters."'' (As of version 5.3:)
 
* The ten ''"metacharacters:"''
Line 520:
: {{Pre |‘space’ ‘tab’ ‘newline’ ‘|’ ‘&’ ‘;’ ‘(’ ‘)’ ‘<’ ‘>’}}
 
''"Blanks"'' are composed entirely of unquoted metacharacters, ''"operators"'' each contain at least one unquoted metacharacter and ''"words"'' may not include any unquoted metacharacters.
 
In practice, Bash breaks down full command strings into tokens or groups of tokens that ''do'' contain "metacharacters" as well asand tokens or groups of tokens that do ''not'' contain any "metacharacters" -- called ''"words."''
From there it further breaks ''words'' down into more specific, meaningful pieces like command names, variable assignment statements, etc.
 
Line 543:
</syntaxhighlight>
 
A ''"word"'' is a sequence of (non-meta-) characters treated as a single unit by the shell.
A ''"reserved word"'' is a kind of a ''"word"'' that has a special meaning to the shell.<ref>
{{Cite web
| access-date = 18 August 2025
Line 551:
}}
</ref>
A ''"name"'' is a kind of a ''"word,"'' separate from ''reserved words'', which consists solely of letters, underscores and numbers; which begins with either a letter or an underscore; which, however, may not begin with a number.
''"Names,"'' also called ''"identifiers,"'' may be used for naming variables and functions.
 
* ''"Words"''
Line 568:
</syntaxhighlight>
 
In thisthe following example of a full command string, ''metacharacters'' have an comma placed above them, {{Code| ,}}, ''reserved words'' have an carrat placed beneath them, {{Code| ^}}, and other ''tokens'' have a backtick placed also beneath them, {{Code| `}}.
 
: <syntaxhighlight lang = console>