The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
division operation in shell script ragha81 Shell Programming and Scripting 31 10-23-2006 06:43 PM
Difference between writing Unix Shell script and AIX Shell Scripts haroonec AIX 0 04-12-2006 03:27 AM
shell scripts help ccp Shell Programming and Scripting 2 11-10-2005 03:31 AM
about shell scripts scottl UNIX for Dummies Questions & Answers 5 08-20-2003 09:54 AM
shell scripts karenshaw Shell Programming and Scripting 1 06-12-2002 09:17 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-28-2005
esham's Avatar
esham esham is offline
Registered User
  
 

Join Date: Nov 2004
Location: INDIA
Posts: 107
division in shell scripts

Iam not able to device variables in a shell script..
here is the lines that i tried.. please help..

sum = echo `expr $up / ( $down )`
  #2 (permalink)  
Old 11-28-2005
mona's Avatar
mona mona is offline
Registered User
  
 

Join Date: Nov 2005
Location: Singapore
Posts: 96
Quote:
Originally Posted by esham
Iam not able to device variables in a shell script..
here is the lines that i tried.. please help..

sum = echo `expr $up / ( $down )`
Try like this,

sum=$(print "scale = 2; $up/$down" | bc)
  #3 (permalink)  
Old 11-28-2005
ashterix ashterix is offline
Registered User
  
 

Join Date: Nov 2005
Location: cyberjaya
Posts: 85
try

$ sum=`expr $up / $down`
$ echo $sum
  #4 (permalink)  
Old 11-28-2005
mona's Avatar
mona mona is offline
Registered User
  
 

Join Date: Nov 2005
Location: Singapore
Posts: 96
Quote:
Originally Posted by ashterix
try

$ sum=`expr $up / $down`
$ echo $sum
You will not get decimal points with this solution if the $down value is greater than $up value.
  #5 (permalink)  
Old 11-30-2005
esham's Avatar
esham esham is offline
Registered User
  
 

Join Date: Nov 2004
Location: INDIA
Posts: 107
print command is not found message is coming.
my division will give less that 0 value..
so what to do..
any other option for print
  #6 (permalink)  
Old 11-30-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
Replace the print with echo.
  #7 (permalink)  
Old 11-28-2005
rahulrathod rahulrathod is offline
Registered User
  
 

Join Date: Sep 2004
Location: Mumbai-India
Posts: 158
Try this

div=$(($x / $y))

This will store the result of division in the div variable.

Regards,
Rahul.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:59 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0