Bash Command Line Expansion: Difference between revisions
Line 22: | Line 22: | ||
===Brace Expansion=== | ===Brace Expansion=== | ||
Brace expansion is the process of expanding a set of ''comma-separated'' strings specified inside the braces into a ''space-separated'' list of strings. Each string from the list is prepended with a ''preamble'', and appended with the ''postscript''. Both the preamble and the postscript are optional. The left-to-right order of the strings within the braces is preserved in the expansion. Brace expansion occurs only if at least one comma exists inside the braces. Brace expansions can be nested. | |||
===Tilde Expansion=== | ===Tilde Expansion=== |
Revision as of 00:23, 9 September 2017
External
Internal
Overview
Process
Each line read by bash from command line is interpreted as a pipeline: a sequence of commands separated by the pipe character (|).
Command processing starts by checking the first word of the command against an alias list, and if a match is found, the alias is replaced.
Then the result is parsed into tokens by using metacharacters as separators.
Command Line Expansion
The token are scanned to perform command line expansion, which are the following operations, performed in order:
Brace Expansion
Brace expansion is the process of expanding a set of comma-separated strings specified inside the braces into a space-separated list of strings. Each string from the list is prepended with a preamble, and appended with the postscript. Both the preamble and the postscript are optional. The left-to-right order of the strings within the braces is preserved in the expansion. Brace expansion occurs only if at least one comma exists inside the braces. Brace expansions can be nested.
Tilde Expansion
Parameter and Variable Expansion
Arithmetic Expansion
Command Substitution
Word Splitting
Pathname Expansion
Process Substitution
Quote Removal
After all command line expansion specified above are performed, bash proceeds with quote removal: it removes from the command line single quotation marks, double quotation marks and backslashes that are not a result of an expansion.