Skip to main content
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.

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.
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.
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.
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.

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.
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.
Tired of Poor Bash Skills? Fix That With Deep Grasping!Learn More