float comparison


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting float comparison
# 1  
Old 09-14-2005
Question float comparison

I had a variable 1:80 8 in one varialbe say var=1:80 8

i comapred the below

if [ $var = "1:80 8" ]
then
--
else
----

thought if condition is true its always going in the else condition....its not giving any compilation errror also....is there any problem bcoz of space...

can some one help me out
# 2  
Old 09-14-2005
Try this:
Code:
if [ "$var" = "1:80 8" ]
then
--
else
----

Also, as a good practice, use " " around variable names that are used for comparison.
# 3  
Old 09-14-2005
mkan, you had a similiar post please help immediate which was locked because one of ours mods thought it to be a homework question. I shall not go against that judgement and provide the solution.

But read the man pages of sh. It will give you a better understanding. Look under the sections of QUOTING

Edit. Looks like the solution is already provided.
# 4  
Old 09-14-2005
Quote:
Originally Posted by vino
mkan, you had a similiar post which was locked because one of ours mods thought it to be a homework question. I shall not go against that judgement and provide the solution.

But read the man pages of sh. It will give you a better understanding. Look under the sections of QUOTING

Edit. Looks like the solution is already provided.
I dont think that this question falls under the "homework" category. The OP is not asking for a readymade solution for some problem - we get many more questions where the OP just asks "How do I..." without saying that they have actually done about it. This question refers to a single line in code that the OP has already written - I think that the doubt is legitimate, especially if you are new to scripting.

Last edited by blowtorch; 09-14-2005 at 02:57 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to declare float in shellscript?

Hi All, I am having an abc.txt , which contains some digits Eg:abc.txt 14.5 56.6 95.5 I want write shellscript in suchway that if any digit is greter than 90 then it shuld display " digit is greater than 90" Please help me to do so .I have tried below code , for... (5 Replies)
Discussion started by: pspriyanka
5 Replies

2. Red Hat

What is float IP?

:confused:We have two servers one active and one stand by as follows Active 202.61.9.9 Stand by 202.61.9.10 Float IP 202.61.9.8 What is use of this float IP? How it is configured? (1 Reply)
Discussion started by: manalisharmabe
1 Replies

3. Shell Programming and Scripting

float to normal

I have a file with 2 columns . One of the line looks like the following. Is it possible to convert every float no in column 2 to integer. input NM_032881 6.03787973608527e-05 output 0.0000603787..... (2 Replies)
Discussion started by: quincyjones
2 Replies

4. UNIX for Advanced & Expert Users

Get Minimun from a Float values

Hi Guys, here is a part of my source code. This part is reponsible to get the minimun of a few values: .......... MAX=0.00 for a in `cat $OFILE` do if then ... (2 Replies)
Discussion started by: Paat
2 Replies

5. Programming

Float issues

i am adding two floating point numbers and i want to store in a character pointer... float f1 ; float f2 ; char *c = NULL; printf("Enter 2 floating numbers\n"); scanf("%f %f",&f1,&f2); f1 = f1+f2; sprintf(c, "%f", f1 ); when i execute this, i am... (3 Replies)
Discussion started by: pgmfourms
3 Replies

6. Programming

comparison between float numbers

Hi, i have a simple control like this: if(sum>1.0)... If i try to print sum i get 1.000000 but the check returns true. I think it depends on float precision. How can i modify the check? thanks (1 Reply)
Discussion started by: littleboyblu
1 Replies

7. Shell Programming and Scripting

float input

how to input float data type in bash shell programming in linux? I am new to it so unaware to use the commands plz help me out. thank you. (6 Replies)
Discussion started by: purva
6 Replies

8. Shell Programming and Scripting

Float and Double in Perl

HI! What is the notation which correspond to C's doubleandfloatin Perl?? Please tell me. Thanks. Well what I want to do is, for example, calculatingsqrt(2)in two way: float and double. (5 Replies)
Discussion started by: Euler04
5 Replies

9. Programming

math.h: float ceilf(float x)

Good morning, I'm testing the use of ceilf: /*Filename: str.c*/ #include <stdio.h> #include <math.h> int main (void) { float ceilf(float x); int dev=3, result=0; float tmp = 3.444f; printf("Result: %f\n",ceilf(tmp)); return 0; } (1 Reply)
Discussion started by: jonas.gabriel
1 Replies

10. UNIX for Dummies Questions & Answers

Float calculations

As expr is used for integer calculations, which command is used for float calculations. (1 Reply)
Discussion started by: sharmavr
1 Replies
Login or Register to Ask a Question