Adnan Adnan - 1 year ago 91
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