How to pass results of bc to a variable
Posted
by
shaolin
on Ask Ubuntu
See other posts from Ask Ubuntu
or by shaolin
Published on 2012-12-15T21:59:46Z
Indexed on
2012/12/15
23:19 UTC
Read the original article
Hit count: 266
I'm writing a script and I would like to pass the results from bc
into a variable. I've declared 2 variables (var1
and var2
) and have given them values. In my script I want to pass the results from bc
into another variable say var3
so that I can work with var3
for other calculations. So far I have been able write the result to a file which is not what I'm looking for and also I've been able to echo the result in the terminal but I just want to pass the result to a variable at moment so that I can work with that variable.
echo "scale=2;$var1/var2" | bc
© Ask Ubuntu or respective owner