LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 12-13-2004, 08:48 AM   #1
sharadgana
LQ Newbie
 
Registered: Dec 2004
Posts: 7

Rep: Reputation: 0
Shell Programming


Hi iam new to shell programming. I have Elx Linux installed. I have to do floating point arthimetic but the bc command doesn't seem to work. Is there any alternate way to do this. i have checked man bc but it says there is no manual on that . i think there is no bc installed in the linux



Pls help

Sharad
 
Old 12-13-2004, 09:58 AM   #2
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,994

Rep: Reputation: 76
EIX looks to be an RPM-based distribution. You can download a source RPM for bc from www.rpmfind.net, and compile it with
Code:
rpmbuild --rebuild bc*.srpm
You can then install the generated RPM file (which I think goes somewhere like /usr/share/RPM/build/RPM/i386/bc-something.rpm) using
Code:
rpm --install /path/to/bc*.rpm
You will need to run both commands as root
Code:
su
 
Old 12-14-2004, 06:09 AM   #3
mayur
LQ Newbie
 
Registered: Jun 2003
Posts: 14

Rep: Reputation: 0
try with bc -l
 
Old 12-14-2004, 06:44 AM   #4
bahramH
Member
 
Registered: Apr 2004
Location: France
Distribution: Mandrake
Posts: 67

Rep: Reputation: 15
I find it very usefull to write small C programs to be included in a shell script. There are things you do much more easliy with a standandard language than by learning each time all the options of a utility like bc (which somebody else has written in C some times before). for exemple, do_arith.c

#include <stdio.h>
main(int argc, char *argv[])
{
double x,y;
sscanf(argv[1],"%lf",&x);
sscanf(argv[2],"%lf",&y);
return(x+y);
}

compile it
gcc -o do_arith do_arith.c


and now, if in your shell script you want to add 23.4 and 44.2, just use

do_arith 23.4 44.2


Of course, if what you wan't to do is much more complicated than that, you should use bc or the like. Very often however, writing a small piece is faster than fishing the RPM, installing it, learning the synthax and so on.
 
Old 12-14-2004, 07:35 AM   #5
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
Quote:

x=$(perl -e 'print 12 / 5.9')
echo $x
2.03389830508475
regards billy
 
Old 12-14-2004, 07:42 AM   #6
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
Or using 'dc' which is the back-end to bc

using precision of 12:

Quote:

echo 12k 12 5.9 / p | dc
2.033898305084
 
  


Reply



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
Shell programming quan Programming 8 11-27-2005 07:46 PM
shell programming qerf Linux - Newbie 5 11-06-2005 05:28 PM
programming shell tuls Slackware 3 08-24-2005 05:58 PM
new to shell programming bluetwist Debian 3 08-01-2005 03:56 PM
Shell Programming eantoranz Linux - Networking 2 06-02-2005 11:21 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:20 AM.

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
Open Source Consulting | Domain Registration