Using variables in for loops bash [duplicate]

Solution 1:

It prints out 5 four times because { eval echo {0..2}} results in four whitespace-separated tokens {, 0, 1 and 2}

If you want to use $1 as the end of a range expression in bash, it's better to use the external seq command:

for number in $(seq "$1")

or use a C-style for loop

for ((number=0; number<"$1"; number++))