The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Add non-integers using ksh 2dumb Shell Programming and Scripting 18 04-13-2009 01:28 AM
How to represent euro sign in unix akash Shell Programming and Scripting 1 01-22-2008 03:50 PM
integers in the if statement Deanne Shell Programming and Scripting 5 01-22-2008 05:14 AM
How do you represent a field delimeter that is a space??? TRUEST UNIX for Dummies Questions & Answers 1 05-04-2003 10:01 PM
What is $PROD ? Does it represent some Unix directory? Ashishm Shell Programming and Scripting 2 02-11-2002 05:53 AM

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 05-18-2003
TRUEST TRUEST is offline
Registered User
  
 

Join Date: Jan 2002
Posts: 144
how do you represent non integers in a shell script?

am trying to write a script that test that the load average which is taken from the uptime command's output to make sure it doesn't pass a certain limit. each time I execute the script, it complains about interger errors.

if [ $LOAD -gt $MAX ]
  #2 (permalink)  
Old 05-18-2003
oombera's Avatar
oombera oombera is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2002
Location: Cleveland, OH
Posts: 804
Are you certain that this line is where the code stops executing? Are you sure that $LOAD and $MAX actually contain numerical values? Could you post some more of the code?
  #3 (permalink)  
Old 05-18-2003
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,131
If you have a value like "4.00", just get rid of the dot and you have "400". Now it is integers, but it is multipled by 100. So to compare another number to it, do the same to the other number as well.

If you have "MAX=4.00", then do
MAX=$(echo $MAX | sed 's/\.//')
to get rid of that dot.

But if you have "MAX=4", you need to muliply by 100. But, just toss a couple of zeros on the end:

MAX="${MAX}00"

This is quicker than a real multiply.
Closed Thread

Bookmarks

Tags
load average, performance

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 02:40 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