Unless you want to implement a complete mathematical expression interpreter (which could be easy or difficult, depending on how complex you want the expression support to be) you could simply pass the expression to an external utility which is designed to do that job already, e.g. bc.
Code:
awk '
BEGIN {
str="2+2"
"echo " str " | bc " | getline result
print result
}
'
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.