bash: $[<arithmetic-expression>] vs. $((<arithmetic-expression>)) bash: $[<arithmetic-expression>] vs. $((<arithmetic-expression>)) bash bash

bash: $[<arithmetic-expression>] vs. $((<arithmetic-expression>))


The manpage for bash v3.2.48 says:

[...] The format for arithmetic expansion is:

     $((expression))

The old format $[expression] is deprecated and will be removed in upcoming versions of bash.

So $[...] is old syntax that should not be used anymore.


@sth is entirely correct. And in case you are curious about why a more verbose syntax is now in favor, check out this old email from the mailing list.

http://lists.gnu.org/archive/html/bug-bash/2012-04/msg00033.html

“In early proposals, a form $[expression] was used. It was functionallyequivalent to the "$(())" of the current text, but objections werelodged that the 1988 KornShell had already implemented "$(())" andthere was no compelling reason to invent yet another syntax.Furthermore, the "$[]" syntax had a minor incompatibility involvingthe patterns in case statements.”

I am not sure that I like the rationale “but someone has already done this more verbosely,” but there you have it—maybe the case-statement problem was more compelling than I am imagining from this obscure mention?