how do you represent non integers in a shell script?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers how do you represent non integers in a shell script?
# 1  
Old 05-18-2003
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  
Old 05-18-2003
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  
Old 05-18-2003
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.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep float/integers but skip some integers

Hi, I am working in bash in Mac OSX, I have following 'input.txt' file: <INFO> HypoTestTool: >>> Done running HypoTestInverter on the workspace combined <INFO> HypoTestTool: The computed upper limit is: 11 +/- 1.02651 <INFO> HypoTestTool: expected limit (median) 11 <INFO> HypoTestTool: ... (13 Replies)
Discussion started by: Asif Siddique
13 Replies

2. Shell Programming and Scripting

Editing lists of integers in 1d files with bash shell

Hi, I need a script that will: 1. Go through about 20 different folders, each containing about 20 1d files. The 1d files go something like this: 22.253 37.707 78.117 112.374 127.944 156.067 180.956 233.785 249.256 ... (1 Reply)
Discussion started by: ac130pilot
1 Replies

3. UNIX for Dummies Questions & Answers

What does $ represent in command prompt?

What does $ represent in command prompt? (2 Replies)
Discussion started by: ashok.g
2 Replies

4. Shell Programming and Scripting

Passing Integers to shell script from java

i have to pass an integer value to shell script which will mail the values to users. I am able to pass string values like this. try { String strCmdToRun1 = new String { "sh", "mail.sh","hello"}; Process p1 = rtime.exec(strCmdToRun1); BufferedReader output... (1 Reply)
Discussion started by: naveensraj
1 Replies

5. UNIX for Dummies Questions & Answers

Why does Linux use files to represent drives?

Why does Linux use files to represent drives such as pipes and network connections? (2 Replies)
Discussion started by: MS_CC
2 Replies

6. Solaris

Disk Representation - what is this c1t1d0s2 represent?

Hi All, Can you please advise what the 't' letters stands for? I understand the letter for the following "c1t1d0s2": c = disk Controller t = ? d = disk number ID. s = slice or partition of the disk Thanks (2 Replies)
Discussion started by: tlee
2 Replies

7. Shell Programming and Scripting

shell script that adds two integers and display answer on screen

please help shell script that adds two intergers and display answer on screen (1 Reply)
Discussion started by: wanyac2
1 Replies

8. Shell Programming and Scripting

How to represent euro sign in unix

how should represent euro sign "€" in Unix (1 Reply)
Discussion started by: akash
1 Replies

9. UNIX for Dummies Questions & Answers

How do you represent a field delimeter that is a space???

you know like if you want to work on a specified field in the password file. you would specify the field your interested in my telling the script that the fields are separated by a colon. now, my problem is that I want to specify a field that is not separated by a colon but by a space or tab... (1 Reply)
Discussion started by: TRUEST
1 Replies

10. Shell Programming and Scripting

What is $PROD ? Does it represent some Unix directory?

Hi , Could u tell me What is $PROD ? Does it represent some Unix directory? Regards Ashish Malviya (2 Replies)
Discussion started by: Ashishm
2 Replies
Login or Register to Ask a Question