Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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};
    echo "Iteration $i"

will print:

Iteration {1..3}

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

share|improve this question
This error occur if the script is executed by the "sh" command (try using "bash"). – Shake0 Jul 22 '12 at 3:39
up vote 5 down vote accepted

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};
    echo "Iteration $i"
Iteration 1
Iteration 2
Iteration 3

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

share|improve this answer
You are right! I thought sh and bash were the same thing.. – Shake0 Jul 22 '12 at 3:36
no, bash and sh are quite different... bash is more capable than sh, it was made on the shoulders of sh :) although they both have a good degree of compatibility, they also have its differences – zipizap Dec 12 '13 at 14:13
note that you can do nested lists like for var in {{i..j},{l..m}};do echo $var;done if you need irregular sequence such as 1 2 3 7 8 9 – brown.2179 May 9 '14 at 15:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.