Recommended Free Tools
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.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Scan for outdated or missing drivers - takes under a minute3Repair Windows errors before they cause bigger problemsThe same structure works for a countdown by changing the initial value, condition, and step:
#1 Best Overall
- Used Book in Good Condition
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:
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutefor 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.
Rank #4
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.
Quick Recap
Best Value
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.

