Sponsored Content
Top Forums Shell Programming and Scripting Which is the best way/command to do mathematics in UNIX scripting? Post 302403951 by hakermania on Monday 15th of March 2010 07:03:45 AM
Old 03-15-2010
Question 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
Code:
(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:
Code:
read lol
read lil
echo "scale=2; $lol - $lil" | bc

bc gives error.The only way to avoid this error is this way:
Code:
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
Code:
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????
 

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

mathematics operations in unix

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)
Discussion started by: cesar720213
2 Replies

2. UNIX for Dummies Questions & Answers

mathematics in shell script

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)
Discussion started by: sureshy
2 Replies

3. Shell Programming and Scripting

difference between AIX shell scripting and Unix shell scripting.

please give the difference between AIX shell scripting and Unix shell scripting. (2 Replies)
Discussion started by: haroonec
2 Replies

4. Shell Programming and Scripting

hell & mathematics

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)
Discussion started by: ogoy
5 Replies

5. Shell Programming and Scripting

recommend book for unix command/ shell scripting

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)
Discussion started by: nurulamin862
1 Replies

6. UNIX for Dummies Questions & Answers

Unix Shell Scripting( Calling from Unix to PLSQL)

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)
Discussion started by: faizsaadq
1 Replies

7. Shell Programming and Scripting

If else condition inside for loop of awk command in UNIX shell scripting

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)
Discussion started by: karthikram
2 Replies

8. What is on Your Mind?

Forum Trivial Pursuit - New Computer Science and Mathematics Trivia for UNIX.com

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)
Discussion started by: Neo
20 Replies
SSI_Parser(3)						User Contributed Perl Documentation					     SSI_Parser(3)

NAME
CGI::SSI_Parser - Implement SSI for Perl CGI SYNOPSIS
use CGI::SSI_Parser; $CGI::SSI_Parser::recursive = 1; fssi($filename); sssi($string); DESCRIPTION
CGI::SSI_Parser is used in CGI scripts for parsing SSI directives in files or string variables, and fully implements the functionality of apache's mod_include module. It is an alternative to famous Apache::SSI modules, but it doesn't require mod_perl. This is an advantage to those who are using public hosting services. There is a disadvantage, however - the module consumes much memory, and I don't recommend using it on heavy-loaded sites (currently it's being used on a site with 10000 hits, and I consider this as a limit). I hope to get rid of this disadvantage by the time the release comes out (currently it's beta). SSI Directives This module supports the same directives as mod_include. For methods listed below but not documented, please see mod_include's online docu- mentation at http://httpd.apache.org/docs/mod/mod_include.html . o config o echo This directive is not fully supported in current version. o exec o fsize o flastmod o include o printenv o set This directive is not supported in current version. o perl This directive is not supported in current version. o if o elif o else o endif These four directives are not supported in current version. Outline Usage First you need to load the CGI::SSI_Parser module: use CGI::SSI_Parser; You need to specify the following when processing of all nested directives is needed (default value - 0): $CGI::SSI_Parser::recursive = 1; To parse file or string you need to use: fssi($filename); sssi($string); The result is printed to STDOUT. TO DO
Full implementation of all SSI directives. Optimize memory consumption. AUTHOR
Vadim Y. Ponomarenko, vp@istc.kiev.ua SEE ALSO
mod_include, perl(1). perl v5.8.0 2001-01-06 SSI_Parser(3)
All times are GMT -4. The time now is 08:26 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy