[ (Left Square Bracket) is ASCII code point 91 (0x5B), Unicode U+005B, and a printable punctuation character. It opens a bracketed enclosure — in prose, it typically marks editorial insertions or clarifications within quoted text, signaling that the words inside came from someone other than the original speaker. Programming made square brackets the universal indexing operator. array[0] retrieves the first element in C, Python, JavaScript, Java, Ruby, and nearly every language that supports random access. Python extends the notation into slicing (list[1:4]), and JavaScript uses brackets for dynamic property access (obj["key"]) when dot notation won't work — particularly when the key contains spaces or is stored in a variable. In regular expressions, [abc] defines a character class, matching any single character from the set inside. JSON uses [ to open arrays, and Bash leans on [ as a synonym for the test command in conditionals. The trap is subtle and language-specific: in C, array indexing performs no bounds checking, so array[10] on a five-element array doesn't raise an error — it silently reads whatever garbage happens to occupy that memory address, producing results that change between runs and vanish under a debugger. Square brackets entered typographic use around the seventeenth century, introduced by printers who needed a visual distinction from the already-established parentheses to denote a different kind of enclosure. UTF-8 encodes it as a single byte 0x5B. Unicode classifies it as Ps (Punctuation, Open) with the name LEFT SQUARE BRACKET. Its closing partner ] sits at U+005D, and the fullwidth [ (U+FF3B) appears in CJK text — a wider glyph that will quietly break any parser expecting the ASCII original.
char s[] = "[OK]";char tag = s[0]; // '[' at the starts[0] = '('; // edit by indexing/* s is now "(OK]" */
Square brackets serve three main purposes: array indexing (arr[0]), array/list creation ([1, 2, 3] in Python/JavaScript), and computed property access (obj['key']). In regex, [abc] defines a character class. In Bash, [ is actually a command (test) with ] as its closing argument.
In CLI documentation and man pages, [optional] means the argument is optional. In BNF grammar notation, they indicate optional elements. In Markdown, [text](url) creates a link. In JSON Schema, they define array types. The convention of 'brackets = optional' is nearly universal.
In Bash, [ is literally /usr/bin/[ (or a shell builtin) — it's the 'test' command that evaluates conditional expressions. The ] is just a required final argument. This is why spaces are mandatory: [ -f file ] works, but [-f file] fails because 'test' needs its arguments separated.
[abc] matches any single character in the set (a, b, or c). [^abc] matches any character NOT in the set. [a-z] matches any lowercase letter. Inside brackets, most metacharacters lose their special meaning — . is a literal dot, not 'any character.' Only ^, -, ], and \ are special inside [ ].