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 zero-padded sequence is a specific form of Bash brace expansion that generates a contiguous range of integers formatted with leading zeros to enforce a uniform string width. Introduced in Bash 4.0, the expansion engine evaluates the maximum character width of the specified boundaries and pads all generated elements to match that width.

Syntax


# Basic zero-padded sequence
{0START..END}
{START..0END}


# Zero-padded sequence with a step increment
{0START..0END..INCREMENT}

Evaluation Mechanics

  • Width Determination: The total width of every element in the generated sequence is dictated by the boundary parameter (START or END) with the greatest number of characters. To trigger the padding behavior, the absolute value of either boundary must be prefixed with a 0 (e.g., 05 or -05).
  • Textual Expansion vs. Arithmetic: Brace expansion is a textual/string expansion that occurs before arithmetic evaluation. Consequently, leading zeros in brace expansion denote formatting width, not octal numbers. For example, {01..010} expands up to base-10 10, whereas an actual arithmetic operation like $((010)) evaluates to base-10 8.
  • Negative Integers: When generating sequences that include negative numbers, the minus sign (-) is calculated as part of the total string width. The zero-padding is inserted strictly between the minus sign and the integer.
  • Order of Expansion: Brace expansion is the very first step in the Bash shell expansion process. It occurs strictly before parameter and variable expansion. Consequently, variables cannot be used to define the START, END, or INCREMENT values dynamically without utilizing eval.
  • Type Restriction: Zero-padding applies exclusively to integer sequences. It cannot be used with alphabetic character sequences. Because Bash requires alphabetic sequence boundaries to be exactly one character long, prefixing a character with a zero (e.g., {0a..z}) fundamentally breaks the sequence syntax. The expansion engine rejects it entirely, leaving the expression as an unexpanded literal string.

Syntax Visualization

Standard Padding: The width is determined by 005 (3 characters). The starting integer 1 is padded to 001.
$ echo {001..005}
001 002 003 004 005
Asymmetric Padding Definition: Only one boundary requires the zero prefix to trigger the behavior. The longest string (010) sets the width to 3.
$ echo {1..010}
001 002 003 004 005 006 007 008 009 010
Stepped Increment: Generates a sequence from 0 to 15, incrementing by 5, padded to a width of 2.
$ echo {00..15..5}
00 05 10 15
Negative Integer Padding: The width is determined by -05 (3 characters). Positive numbers in the sequence are padded to 3 characters, while negative numbers use one character for the minus sign and are padded to fill the remaining two characters.
$ echo {-05..05..5}
-05 000 005
Master Bash with Deep Grasping Methodology!Learn More