What does a dollar sign followed by a square bracket $[...] mean in bash?
In a thread on the GNU bash mailing list, it says that the $[
syntax was an early syntax that was deprecated in favor of $((
, since the latter was already used by the Korn shell.
According to this site, the manual for bash 3.2.48 contained a reference to the $[
syntax. So presumably this reference had been removed in 3.2.51.
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.