Bash – Meaning of Dollar Sign Followed by Square Bracket $[…]

arithmeticbash

It appears that $[expr] performs arithmetic expansion just like $((expr)). But I can't find any mention of $[ in the bash manual. This command gives no results:

gunzip -c /usr/share/man/man1/bash.1.gz | grep -E '\$\['

What is this operator and is its behavior standardized anywhere?

My bash version: GNU bash, version 3.2.51(1)-release (x86_64-apple-darwin13)

Best Answer

You can find old bash source here. In particular I downloaded bash-1.14.7.tar.gz. In the documentation/bash.txt you will find:

Arithmetic Expansion

Arithmetic expansion allows the evaluation of an arithmetic expression and the substitution of the result. There are two formats for arithmetic expansion:

     $[expression]

     $((expression))

The references to $[ are gone in doc/bash.html from the bash-doc-2.0.tar.gz download and the NEWS file mentions that:

The $[...] arithmetic expansion syntax is no longer supported, in favor of $((...)).

$((...)) is also the standard syntax for an arithmetic expansion, but may have been added to the standard later than the original Bash implementation.

However, $[...] does still seem to work in Bash 5.0, so it's not completely removed.

Related Question