Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

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

Assuming var1 = 5 for example.

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

1 Answer

up vote 4 down vote accepted

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.
share|improve this answer
    
You beat me to the answer while I was looking for this manpage snippet. –  jordanm Mar 5 '13 at 21:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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