Hello all!
I used to use expr for doing simple mathematics, but has a main advantage and a main disadvantage:
The advantage is that it can take variables for numbers
(e.g.{1}: echo "Give me first"
read lol
echo "Give other"
read lil
sum=`expr $lol + $lil`
echo "The sum of $lol and $lil = $sum")
The disadvantage is that it cannot give float numbers.It gives errors (example for 2 / 5 .......)
Somebody told me about bc but I cannot give him variables.The program I wanna make is similar to example {1} but I need float numbers!
if the program is like this:
read lol
read lil
echo "scale=2; $lol - $lil" | bc
bc gives error.The only way to avoid this error is this way:
lol=5 ; lil=2 ; echo "scale=2; $lol - $lil" | bc
But in this way you don't allow the user to choose himself the variables.
Somebody told me that
read lol
read lil
echo "scale=2; $lol - $lil" | bc
works, but unfortunately in my OS doesn't work(Ubuntu 9.10)
Any suggestions/ideas????