Brace expansion happens early.
Parameter expansion happens later, so you can't use variables or other parameters in a way that controls brace expansion.
The order of expansions is: brace expansion, tilde expansion, parameter, variable and arithmetic expansion and command substitution (done in a left-to-right fashion), word splitting, and pathname expansion.
This will prevent statements like for i in {000..0$n4} ; do
from working as intended.
Also, be sure to remember the -v
and -x
arguments to display the actual commands executed.