Setting up the reverse machine for 1990.
Bash implemented the $[] syntax on POSIX P1003.2d9 (circa 1990), which was a project released by P1003.2-1992. For two years between the project and the POSIX standard, the syntax and behavior of ksh88 $(()) set instead. Chet Reime (bash escort) said the following: in 2012 :
Bash ... implemented $ [...] because there was no other syntax at the time and gain some experience with arithmetic expansion in the shell. Bash -1.14 ... lists both forms of arithmetic expansion, but Bash -2.0 was released in 1995, the manual only concerned the form $ ((...)).
This tells me that the $[] form was experimental, and it had a certain behavior (like curly brace extension) that was forgotten when POSIX adopted the $(()) syntax $(()) . Those experimental behaviors remained, since scenarios in the wild already existed relying on them (remember that more than two years have passed).
Chet clearly indicates that the form $[] deprecated, but not deprecated:
Now itβs hardly worth dragging the syntax of $ [...]. Only a few dozen bytes of code are required. I have no plans to remove it.
current POSIX standard, C.2.6 Word Extensions> Arithmetic extensions mention the syntax (my emphasis):
Earlier sentences used the form $ [expression]. It was functionally equivalent to the "$ (())" of the current text , but it was objected that KornShell already implemented "$ (())" in 1988, and there was no good reason to come up with another syntax. In addition, the syntax "$ []" was slightly incompatible, including patterns in case statements.
Thus, the behavior in bash is not completely specified, but since there are no plans to remove it, I see no reason to abandon its benefits if it accurately solves your problem. However, as @Barmar commented, it would be a good idea to comment on the code and link it here so that future developers know what the hell you mean!
bishop Oct 14 '16 at 17:28 2016-10-14 17:28
source share