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 sequence expression is a mechanism within Bash’s brace expansion phase that generates a contiguous series of integers or characters. It evaluates strictly before other expansions (such as parameter expansion, command substitution, or arithmetic expansion) and produces a space-separated list of discrete string tokens.
{<START>..<END>[..<STEP>]}

Parameters

  • START: The initial boundary value. Must be an integer or a single alphabetic character.
  • END: The terminal boundary value (inclusive). Must match the data type of START.
  • STEP (Optional): An integer defining the interval between generated values. Bash evaluates this as an absolute value, ignoring any negative sign. If omitted, Bash defaults to an interval of 1 or -1, automatically inferred from the relative values of START and END.

Core Mechanics

Integer Sequences Generates a sequence of base-10 integers. It natively supports negative numbers and automatically determines whether to increment or decrement based on the boundaries.

# Ascending
echo {1..5}

# Output: 1 2 3 4 5


# Descending with negative integers
echo {2..-2}

# Output: 2 1 0 -1 -2
Zero-Padding If either START or END is prefixed with a 0, Bash forces all generated tokens to be zero-padded to match the maximum character width of the provided boundary values.
echo {001..5}

# Output: 001 002 003 004 005

echo {08..11}

# Output: 08 09 10 11
Character Sequences Generates a sequence of single characters based on the C locale’s lexicographical order (ASCII code points). While the START and END boundaries must be standard alphabetic characters to trigger the expansion, the generated sequence itself is not strictly alphabetic. Mixing cases (e.g., {a..Z}) traverses the ASCII table between the two code points, outputting the non-alphabetic characters ([, \, ], ^, _, `) that reside between the uppercase and lowercase ranges.
echo {a..e}

# Output: a b c d e


# Mixed case traversal including non-alphabetic ASCII characters
echo {a..Z}

# Output: a ` _ ^ ] \ [ Z
Step Intervals The STEP parameter forces the sequence to skip values. Bash evaluates the STEP as an absolute difference. Syntactically, Bash accepts negative integers for the step but ignores the negative sign, applying the absolute value regardless of whether the sequence is ascending or descending.

# Integer step
echo {10..0..2}

# Output: 10 8 6 4 2 0


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

# Output: 1 3 5


# Character step
echo {a..z..5}

# Output: a f k p u z

Parser Evaluation Constraints

Because brace expansion is the absolute first step in the Bash shell expansion process, sequence expressions are evaluated as strict literals. They cannot dynamically interpolate variables directly.

# This will NOT evaluate as a sequence expression
END=5
echo {1..$END}

# Output: {1..5}
To force a sequence expression to evaluate variables, the shell must be instructed to perform a secondary evaluation pass using eval, though this requires careful string escaping to prevent premature expansion.
Master Bash with Deep Grasping Methodology!Learn More