What is brace expansion and how is it different from globbing?
BeginnerConceptVariables, quoting and expansions
Answer
Brace expansion generates strings whether or not files exist; globbing matches existing files.
mkdir -p /srv/app/{releases,shared/{logs,config}}
cp nginx.conf{,.bak} # cp nginx.conf nginx.conf.bak
echo web{1..3}.prod # web1.prod web2.prod web3.prod
echo {01..10..3} # 01 04 07 10
Brace expansion happens first and does not work with variables: {1..$n} stays literal. Use seq 1 "$n" or a C-style for ((i=1; i<=n; i++)) loop.
More on Variables, quoting and expansions
What are the rules for assigning variables in Bash?BeginnerWhat is the difference between single quotes, double quotes and `$'...'`?BeginnerWhy should you almost always quote variable expansions? Show what goes wrong.BeginnerExplain the difference between `"$@"`, `"$*"`, `$@` and `$*`.IntermediateWhat do `${var:-default}`, `${var:=default}`, `${var:+alt}` and `${var:?msg}` do?IntermediateHow do you strip prefixes and suffixes with parameter expansion?Intermediate