Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

A Bash step sequence is an extension of brace expansion that generates a discrete, ordered list of integers or single characters separated by a defined interval. It evaluates statically during the shell’s initial parsing phase, strictly prior to tilde expansion, parameter expansion, command substitution, or arithmetic expansion.

Syntax

{<start>..<end>..<step>}

Parameters

  • start: The initial integer or single ASCII character.
  • end: The terminal integer or character. The sequence generation halts at or immediately before this boundary.
  • step: An integer defining the interval between consecutive elements. Bash evaluates this as an absolute value; negative signs are ignored.

Core Mechanics

Directionality Bash automatically infers the direction of the sequence (incrementing or decrementing) based on the relationship between start and end. The step parameter is always treated as a positive absolute magnitude, regardless of the provided sign.

# Ascending sequence
echo {1..10..3}

# Output: 1 4 7 10


# Descending sequence
echo {10..1..3}

# Output: 10 7 4 1


# Negative step value (sign is ignored)
echo {1..5..-2}

# Output: 1 3 5
Type Constraints The start and end parameters must be of the same data type—either both integers or both alphabetic characters. Mixing types or using multi-character strings invalidates the syntax, resulting in no expansion.

# Character sequence
echo {a..k..2}

# Output: a c e g i k


# Invalid mixed-type sequence (remains unexpanded)
echo {1..z..2}

# Output: {1..z..2}
Zero-Padding If either the start or end integer is prefixed with a 0, Bash forces all generated elements to be zero-padded. The padding width is determined by the length of the longest boundary string.

# Zero-padded sequence
echo {05..15..5}

# Output: 05 10 15
Evaluation Order Limitations Because brace expansion is the very first expansion performed by the Bash interpreter, the start, end, and step parameters must be hardcoded literals. Attempting to use variables to define the sequence boundaries or step will fail to generate the sequence. The braces and dots are bypassed during the brace expansion phase because the variables are not yet evaluated as valid integers or characters. The variables are subsequently interpolated during the parameter expansion phase, leaving the braces intact.

# Invalid: Brace expansion occurs before parameter expansion
START=1
END=5
STEP=2
echo {$START..$END..$STEP}

# Output: {1..5..2}
(Note: To achieve dynamic step sequences using variables, developers must use the C-style for ((i=start; i<=end; i+=step)) loop syntax or the external seq binary, as native brace expansion cannot evaluate variables). Version Requirement The step parameter syntax (..step) was introduced in Bash 4.0. In older versions (Bash 3.x), appending a step value will cause the entire expression to be treated as a literal string.
Master Bash with Deep Grasping Methodology!Learn More