Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

To loop over every integer from 1 through 10 in Bash, use for ((i=1; i<=10; i++)); do ...; done or the shorter for i in {1..10}; do ...; done. Both include the endpoints. The arithmetic form makes the counting logic explicit; the brace form is compact but relies on Bash brace expansion.

Count from 1 to 10 with an arithmetic loop

Use this form when you want the starting value, stopping condition, and increment to be clear:

for ((i=1; i<=10; i++)); do
  printf '%sn' "$i"
done

The first expression initializes i to 1. Bash checks i <= 10 before each pass, runs the body when the condition is true, then applies i++. The loop therefore prints each integer from 1 through 10, one per line.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The same structure works for a countdown by changing the initial value, condition, and step:

for ((i=10; i>=1; i--)); do
  printf '%sn' "$i"
done

Bash arithmetic uses fixed-width integers and does not check for overflow; division by zero is an arithmetic error. These details matter more in generalized arithmetic loops than in this small range. See the GNU Bash Reference Manual for the documented loop and arithmetic behavior.

Use brace expansion for a fixed range

For a literal range, brace expansion is shorter:

for i in {1..10}; do
  printf '%sn' "$i"
done

Bash expands {1..10} into the inclusive sequence before the loop runs, then the word-list loop assigns each generated value to i.

Skip values with an increment

Add a third number to set the step. This example prints odd numbers from 1 through 9:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
for i in {1..10..2}; do
  printf '%sn' "$i"
done

Preserve leading zeroes

When an endpoint begins with zero, Bash preserves the sequence’s digit width. For example, {01..10} generates zero-padded values:

for i in {01..10}; do
  printf '%sn' "$i"
done

Brace sequences are inclusive and support an optional increment and zero-padding rules. The Bash Reference Manual documents these expansion details.

Choose the loop that fits your script

Need Use Trade-off
A compact, fixed numeric range for i in {1..10} Concise, but depends on Bash brace expansion.
Explicit counting or adaptable bounds for ((i=1; i<=10; i++)) Shows the control logic directly; still Bash-specific.
Process supplied arguments or other values for i in "$@" Iterates a word list rather than generating a numeric interval; quoting keeps each positional argument as its own item.

Bash also supports the general word-list form for name in words; do commands; done. It runs the body once for each resulting word. Both brace expansion and the arithmetic for ((...)) syntax are Bash features, so neither should be presented as portable POSIX sh syntax.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Check the script’s interpreter

If the script is intended to run in Bash, declare that interpreter in its first line, for example #!/usr/bin/env bash. If it must run under a shell that does not support Bash syntax, choose syntax supported by that shell rather than assuming that {1..10} or for ((...)) will work. Brace expansion happens before other shell expansions, and its behavior can differ from historical sh; the Bash manual notes this compatibility distinction.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.