Recommended Free Tools
To print the numbers 1 through 10 in Bash, use for ((i=1; i<=10; i++)); do printf '%sn' "$i"; done. For a fixed range, the shorter for i in {1..10} form works too. Both include the endpoints; the arithmetic form makes the loop’s counter and stopping condition explicit.
Count from 1 to 10 with an arithmetic for loop
Use Bash’s C-style arithmetic loop when you want to see or adjust the starting value, condition, and increment:
As an Amazon Associate I earn from qualifying purchases.
for ((i=1; i<=10; i++)); do
printf '%sn' "$i"
done
The initialization sets i to 1. Bash checks i<=10 before each run of the body, then i++ adds 1 after each run. The condition includes 10, so the loop prints ten lines, from 1 to 10.
Count down instead
Change the starting value, condition, and increment to count backward:
for ((i=10; i>=1; i--)); do
printf '%sn' "$i"
done
Use brace expansion for a fixed range
For a short, fixed sequence, Bash can expand an integer range into the words the loop iterates over:
#1 Best Overall
- Used Book in Good Condition
for i in {1..10}; do
printf '%sn' "$i"
done
The range includes both 1 and 10. Add a step after a second pair of dots to skip numbers:
for i in {1..10..2}; do
printf '%sn' "$i"
done
This produces 1, 3, 5, 7, and 9. To preserve two-digit formatting, start the range with a zero-padded endpoint:
for i in {01..10}; do
printf '%sn' "$i"
done
Bash preserves the digit width when either endpoint begins with zero, so this sequence is formatted from 01 through 10. The Bash Reference Manual documents integer sequence expansion and the arithmetic loop syntax.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Choose the loop form that fits the job
| Need | Example | Trade-off |
|---|---|---|
| Compact loop over a fixed 1–10 range | for i in {1..10} |
Short, but relies on Bash brace expansion. |
| Visible counter logic or adaptable bounds | for ((i=1; i<=10; i++)) |
Start, condition, and increment are explicit; the syntax is Bash-specific. |
| Iterate over supplied arguments | for i in "$@" |
Runs once per argument rather than generating a numeric range; quoting keeps each argument separate. |
Check the script’s shell before using either form
Both examples use Bash-specific syntax: brace expansion is a Bash feature, and for ((...)) is Bash’s arithmetic loop form. If a script is run by another shell or requires strict POSIX sh compatibility, do not assume these forms will work. Declare Bash as the interpreter for a Bash script and run it accordingly. The manual notes that brace expansion happens before other shell expansions and may differ from historical sh behavior.
Keep arithmetic limits in mind
Bash arithmetic uses fixed-width integers available on the system and does not check for overflow; division by zero is an error. These limits are not an issue for a simple 1-to-10 counter, but matter when generalizing arithmetic loops to larger or computed values. See the Bash Reference Manual for its shell arithmetic rules.
Quick Recap
Best Value
Rank #4
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.




