Adnan Adnan - 2 years ago 100
Bash Question

Handling arithmetic expressions in shell scripting

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


echo `expr a*b`

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


echo a*b

Thanks in advance.

Answer Source

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))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download