Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is $(( expr )) equivalent to $[ expr ] in bash? [duplicate]

Possible Duplicate:
bash: $[<arithmetic-expression>] vs. $((<arithmetic-expression>))

The $(( expr )) construct can be used for integer math in bash, e.g.

echo $(( 2*2 + 1 )) # 5

$[ expr ] seems to do to do the same (but isn't documented):

echo $[ 2*2 + 1 ] # 5

Are these constructs equivalent in bash?

like image 960
Eugene Yarmash Avatar asked Nov 23 '25 14:11

Eugene Yarmash


1 Answers

man bash says:

The format for arithmetic expansion is:

        $((expression))

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

like image 166
hmakholm left over Monica Avatar answered Nov 25 '25 09:11

hmakholm left over Monica



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!