What is the difference between the following two shell arithmetic commands:

echo $[ $var1 - 1 ]
echo $(( $var1 - 1 ))

Assuming var1 = 5 for example.

  • In neither case you need the sigil, just echo $[ var1 - 1 ] and echo $(( var1 - 1 )) is enough. – manatwork Mar 6 '13 at 7:01

From man bash:

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


   The old format $[expression] is deprecated and will be 
   removed in upcoming versions of bash.
  • You beat me to the answer while I was looking for this manpage snippet. – jordanm Mar 5 '13 at 21:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.