What are the main categories of shell expansion, in the order Bash performs them?
AdvancedConceptShells, scripts and execution
Answer
- Brace expansion:
{a,b},{1..10} - Tilde expansion:
~,~user - Parameter and variable expansion, arithmetic expansion
$(( )), command substitution$( )and process substitution<( ), left to right - Word splitting on
IFS(unquoted results only) - Pathname expansion (globbing) of unquoted
*,?,[...] - Quote removal
Consequence: x={1..3}; echo $x prints {1..3}, because brace expansion happened before the variable was expanded. And "$var" skips steps 4 and 5, which is why quoting prevents most bugs.
More on Shells, scripts and execution
What is a shell, and how is Bash different from sh, dash and zsh?BeginnerWhat does the shebang line do, and why prefer `#!/usr/bin/env bash` over `#!/bin/bash`?BeginnerWhat is the difference between `./script.sh`, `bash script.sh` and `source script.sh`?BeginnerWhat happens when you type a command name? How does Bash decide what to run?AdvancedWhy must `cd`, `export` and `read` be builtins rather than external programs?IntermediateWhat is the difference between a login, interactive and non-interactive shell, and which startup files run?Intermediate