for i in {1..10}; do echo "$i"; done
In Bash, {1..3}
is expanded to the numbers 1 2 3. You can read more about it in man bash
, search for "Brace Expansion".
By using an expression like this in a for
loop, we can do something for each number in the range. In this example we simply print the number using echo
.
This is Bash specific, it may not work with simply /bin/sh
.
for ((i=1; i<=10; ++i)); do echo $i; done
printf '%s\n' {1..10}