Bash: Brace expansion precedence and loops over ranges
You can use set -x
in your shell script to see it yourself (Debugging Bash scripts)
set -xfor i in $(eval echo "{01..30}"); do echo $idone
And this is the output:
++ eval echo '{01..30}'+++ echo 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30+ for i in '$(eval echo "{01..30}")'+ echo 11+ for i in '$(eval echo "{01..30}")'+ echo 22
To answer your question, the eval
command is presented with two arguments: the string "echo" and the string "{01..30}". The brace expansion occurs when eval
evaluates the statement formed from those two strings.