cancel
Showing results for 
Search instead for 
Did you mean: 

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
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...