Which is the best way/command to do mathematics in UNIX scripting?
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
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:
bc gives error.The only way to avoid this error is this way:
But in this way you don't allow the user to choose himself the variables.
Somebody told me that
works, but unfortunately in my OS doesn't work(Ubuntu 9.10)
Any suggestions/ideas????
read lol
read lil
echo "scale=2; $lol - $lil" | bc
A hunch. How did you execute these three lines?
If you type them one-by-one at the command prompt answering each "read" before typing the next command ... they should work.
If you put them in a shell script and execute the script ... they should work.
If you cut/paste all three lines onto the command line they will fail. This is because the second line becomes the input to the first line meaning that $lol contains the string "read lil" which in turn makes the echo contain rubbish to pass to "bc".
I have added a new experimental "Computer Science and Mathematics Trivia - True or False" section in the discussions, currently under the tags box.
In the future, I plan to
Expand this feature to add more trivia categories from math, science and technology.
Keep track of correct and... (20 Replies)
Hi ,
Please excuse me for opening a new thread i am unable to find out the syntax error
in my if else condition inside for loop in awk command ,
my actual aim is to print formatted html td tag when if condition (True) having string as "failed",
could anyone please advise what is the right... (2 Replies)
Hello Experts,
I have the following questions to be discussed here at this esteemed discussion forum.
I have two Excel sheets which contain Unix Commands llike creating directory the structure/ftp/Copy/Zip etc to basically create an environment. I need help in understanding some of... (1 Reply)
Hi, i wish to learn unix commands and shell scripting.
platform is solaris. but i am focused more on handy unix commands than system administration.
which books do you recommend? (1 Reply)
I've been able to generate output based on the code scarfake provided me (thanks again man).
A little background so everyone more or less knows whats going on:
I needed code that would propagate a database with 100,000 entries, for capacity testing purposes, something like a stress test.
... (5 Replies)
Hi Friends,
I am new to shell scripting and a trying to work this out.
I have a variable called $number.
The value in this variable is 10
I want to display $number - 2 in a mail. The result would be 8
eg.
mail -s 'subject' user <<eof
the result of your calculation is $number - 2... (2 Replies)
Hello guys!
Can say me anybody about operatios with unix, I don't to make operations, only inside in a variable, like this
#y=4
#x=2
#let z=$y-$x
#echo $z
# 2
but I can't to make mathematical operations with decimal like this
#y=3.2
#x=1.5
#let z=$y-$x
#echo $z
# 3
this... (2 Replies)