Adnan Adnan - 6 months ago 13
Bash Question

Handling arithmetic expressions in shell scripting

Kindly tell me that is it necessary to use "expr" keyword.

EG:-

echo `expr a*b`


And where we can simply handle arithmetic expressions using simple arithmetic operators.

EG:-

echo a*b


Thanks in advance.

Answer

The second form will almost surely never do what you want. In Bash, you have a built-in numeric expression handler, though:

A=4; B=6; echo $((A * B))
Comments