3

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

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

Assuming var1 = 5 for example.

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

1 Answer 1

4

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:

          $((expression))

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

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.