**This is an old revision of the document!**

# Arithmetic expansion

$(( <EXPRESSION> )) $[ <EXPRESSION> ]

The arithmetic expression `<EXPRESSION>`

is evaluated and the resulting value replaces the whole `$((...))`

construct:

Please **do not use the second form $[ … ]**! It's deprecated. The preferred and standardized form is

`$(( ... ))`

!

read -p "Enter first operand: " first read -p "Enter second operand: " second echo "The sum is $((first + second))"

**Note** that in Bash you don't need the arithmetic expansion to simply check for a specific value of an integer, this can be done using the arithmetic evaluation compound command:

read -p "Enter a number: " if ((number == 1234)); then echo "Good guess" else echo "Haha... :-P" fi

## Discussion

The line

read -p "Enter a number: "

in the second example should read

read -p "Enter a number: " number

Fixed, thx

Should mention that

`$(())`

form doesn't accept quoted variable names.