Bash for loop with range {#..#}

The {#..#} generate a sequence of numbers or chars, similarly to range() in Python. If I execute the command echo {1..5} in the command line I have:

1 2 3 4 5

Instead the following bash script doesn't work as expected.

for i in {1..3};
do echo "Iteration $i"
done

will print:

Iteration {1..3}

Why?
*I could use seq but I read it's outdate ()

1

1 Answer

I've tried your code (copy paste into a terminal) and it produced a different result from what you posted:

for i in {1..3};
do echo "Iteration $i"
done
#---OUTPUT BELOW---
Iteration 1
Iteration 2
Iteration 3

Im using Linux Mint 12 Lisa (derived from Ubuntu) with bash version 4.2.10(1)-release

4

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like