P. Sravani P. Sravani - 1 year ago 93
Linux Question

Expression as a string (shell scripting)

I have an expression declared as a string and I want the output to be the result of the expression. I am trying to solve it using shell scripting.
For example


expecting output


Thanks in advance.

Answer Source

You need the arithmetic expransion syntax:

$ expr="123+456"
$ answer=$(($expr))
$ echo $answer
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download