It dates from Posix circa 1990 (1003.2d9, of which I've lost my paper
copy). I implemented it after the Berkeley guys, mostly Marc
Teitelbaum, put it into Posix. It ended up getting dropped in favor
of the ksh $((...)) expansion, at which point everyone deprecated the
old $[...]. I removed it from the manual sometime later, but it still
works as it always has.
This all remains true. I probably won't remove it, but nobody should use it
in new code.
The reason I tried $[...] stems from some code I found re. autosetting
the colour of the return code from the previous command, and autosetting
the colour of the prompt depending on user id (PS1). Viz:
# see: http://linuxcommand.org/lc3_adv_tput.php
# blacK Red Green Blue Yellow Magenta Cyan White bolD Normal
unset fcol bcol col
declare -A bcol
declare -A fcol
declare -a col
col=( k r g y b m c w d n )
for i in {0..7}; do
bcol[${col[i]}]="$(tput setab $i)"
fcol[${col[i]}]="$(tput setaf $i)"
done
fcol[d]="$(tput bold)"
fcol[n]="$(tput sgr0)"
#
# user colour: red for root; green for others (>0)
ucol=( "$(tput setaf 1)" "$(tput setaf 2)" )
# exit colour: green for 0; red for errors (>0)
ecol=( "$(tput setaf 2)" "$(tput setaf 1)" )
# I don't know where I found this.
# Probably somewhere in Greg Wooledge's wiki
# I can't find it again, now!!
# note use of [!!$?]
# !!$? in an arithmetic context does a logical negation
# of the exit status twice, which maps 0 to 0, and non-zero to 1.
# also user id [!!$(id -u)]