Arithmetic operations can be performed in Bash scripting using the following methods:
let result=4+6
echo $result # Output: 10
result=$((4 + 6))
echo $result # Output: 10
result=$(expr 4 + 6)
echo $result # Output: 10
Note: In expr, the mathematical operators like '+' should be provided as arguments with spaces around them.
result=$[4+6]
echo $result # Output: 10
result=$((4 + 6))
echo $result # Output: 10
It's important to note that these methods only perform integer arithmetic. If you need floating point arithmetic, you can use a tool like bc or awk.
For example, using bc:
result=$(echo "4+6" | bc)
echo $result # Output: 10