I am having a problem with builtin sequences (ie: not using seq) in Bash when the seq number is a variable. For example, this works and print me 1 2 3:
for i in {1..3};do echo $i;done
but this :
bash-3.2$ a=3;for i in {1..$a};do echo $i;done
fail and print me {1..3} only
This works with ZSH and I know I have an alternative to make a counter thing but wondering if this is a bug or a brace expansion feature!
Other option is to use seq command:
An alternative would be to use the double-parenthesis construct which allows C-style loops:
try this:
Notes:
In Bash, brace expansion is performed before variable expansion. See Shell Expansions for the order.
If you want to use a variable, use C-style
for
loops as in Shawn's answer.