Interview Prep/Shell Scripting/Variables, quoting and expansions

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.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Variables, quoting and expansions