LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 09-01-2003, 03:47 PM   #1
Dimitris
LQ Newbie
 
Registered: Aug 2003
Posts: 13

Rep: Reputation: 0
square root problems - script


Hello there,

I wrote that script with abit of help in the lines commented
I get an error that I can not fix.
Could somebody help ?

#!/bin/bash

RANDOM=$$

let a=`expr $RANDOM % 10`
let b=`expr $RANDOM % 10`
let c=`expr $RANDOM % 10`

echo "A is equal to: "$a
echo "B is equal to: "$b
echo "C is equal to: "$c

d=$(($b*$b-4*$a*$c))

echo "The D is eqaul to: "$d

if (($d>0))
then

z=`echo "sqrt ($b*b-4*$a*$c)" | bc -l`

one=`echo $z | cut -d"+" -f #HERE
two=`echo $z | cut -d"-" -f #HERE

echo "+ Number is equal to: "$one
echo "- Number is eqaul to: "$two

else

./sqrt.txt

fi



Thanks alot,
Later
 
Old 09-01-2003, 11:41 PM   #2
SaTaN
Member
 
Registered: Aug 2003
Location: Suprisingly in Heaven
Posts: 223

Rep: Reputation: 32
I suppose the error is that you haven't mentioned the field-number
Check man cut for more details ....

Welcome to LQ

Last edited by SaTaN; 09-02-2003 at 12:35 AM.
 
Old 09-02-2003, 01:19 AM   #3
SaTaN
Member
 
Registered: Aug 2003
Location: Suprisingly in Heaven
Posts: 223

Rep: Reputation: 32
#!/bin/sh
a=5
b=14
c=4
d=$(($b*$b-4*$a*$c))
SQRT=`echo "sqrt ($d)" | bc -l`
echo $SQRT


Then the output of this code would be

10.77032961426900806250

I think that
"Only one value gets stored in the variable $SQRT....."

Tell me if I am wrong
 
Old 09-02-2003, 03:52 PM   #4
Dimitris
LQ Newbie
 
Registered: Aug 2003
Posts: 13

Original Poster
Rep: Reputation: 0
your are right....strange it was giving me two numbers....does it matter if the variable is $SQRT or $somethingelse ...otherwise It looks strange to me.

Thanks
 
Old 09-02-2003, 11:05 PM   #5
SaTaN
Member
 
Registered: Aug 2003
Location: Suprisingly in Heaven
Posts: 223

Rep: Reputation: 32
Quote:
Originally posted by Dimitris
your are right....strange it was giving me two numbers....does it matter if the variable is $SQRT or $somethingelse ...otherwise It looks strange to me.

Thanks

No it doesn't matter . And as far as I know sqrt() returns only the posiive value
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
mysql - back to square one bshearer *BSD 3 05-29-2005 11:32 AM
Square fonts with CEDEGA? Spooky Linux - Games 1 05-14-2005 03:14 PM
creating shell script that executes as root regardless of who runs the script? m3kgt Linux - General 13 06-04-2004 11:23 PM
square one - how do I make it go? linuxceptic Linux - Wireless Networking 3 02-04-2004 08:23 PM
root square / two solutions - one variable Dimitris Programming 5 08-28-2003 03:47 PM


All times are GMT -5. The time now is 08:30 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration