2

I don’t know this operator $[] and couldn’t find something about it. However I know that next two codes give the same output

a=4
b=1
echo $[a-b] # => 3

and

a=4
b=1
echo $((a-b)) # => 3

So what is $[] operator for, and what’s the difference with $(()) ?

In my zsh shell prompt, when I open any of them and no close them, I have mathsubst written.

phuclv
  • 37,963
  • 15
  • 156
  • 475
Ulysse BN
  • 10,116
  • 7
  • 54
  • 82

1 Answers1

5

Reading man bash says that the old format $[expression] is deprecated and will be removed. Otherwise they should be equivalent.

Arithmetic expansion allows the evaluation of an arithmetic expression and the substitution of the result. The format for arithmetic expansion is:

          $((expression))

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

martin.macko.47
  • 888
  • 5
  • 9
  • 1
    Even the deprecation warning was removed from the man page a while ago, although the syntax is still supported as of `bash` 4.4. – chepner Dec 11 '16 at 00:21