1753701 Members
5014 Online
108799 Solutions
New Discussion юеВ

Evaluate operations

 
SOLVED
Go to solution
ASSIST
Frequent Advisor

Evaluate operations

I have an environment variable with an aritmetic operation very long

RES=4+5+6+76+.....

how i can evaluate this to obtain a result

I try to save this to a file

# echo $RES > op
# bc op

but don't work

thanks!
3 REPLIES 3
John Palmer
Honored Contributor
Solution

Re: Evaluate operations

If RES contains a valid integer arithmetic expression then you could evaluate it like this...

let X=${RES}

If RES contains any spaces then you'd have to change this to'''

let X="${RES}"

So
RES=4+5+6+76
let X=${RES}
print ${X}
91

Regards,
John
john korterman
Honored Contributor

Re: Evaluate operations

Hi,
in ksh you can try this:
# let RES="4+5+6+76+40"
# echo $RES
131

regards,
John K.
it would be nice if you always got a second chance
James R. Ferguson
Acclaimed Contributor

Re: Evaluate operations

Hi:

# RES=4+5+6+76+10
# echo $RES | bc

Regards!

...JRF...