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
expr="123+456"
expecting output
579
Thanks in advance.
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
expr="123+456"
expecting output
579
Thanks in advance.
If you're dealing only in integers, bash can do it:
(( foo=123+456 ))
echo $foo
returns: 579
You need the arithmetic expransion syntax:
$ expr="123+456"
$ answer=$(($expr))
$ echo $answer
579