October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk2 min

How to Print Numbers 1 Through 10 in a Bash Loop

Print 1 through 10 in Bash with an arithmetic for loop or a compact brace expansion, and learn when each form fits.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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:

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.

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

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.

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

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.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.