comparison of number in linux..


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting comparison of number in linux..
# 1  
Old 03-05-2012
comparison of number in linux..

hi all experts,


Code:
i=1;
while [ $i -lt 5  ]
                do
echo $i
$i=$i+1

done

can I use

Code:
min=2
max=5

if  (($min > $ max))

then 
else
fi


are both correct?

I am always getting errors and need help of experts.

I want to print all integer values less than five.

Actally I want to know if I used WHILE correctly and secondly about the
condition.

if possible please also give idea about real value comparison.
# 2  
Old 03-05-2012
Code:
i=1;
while [ $i -lt 5  ]
do
    echo $i
    i=$(($i+1))
done

Code:
min=2
max=5

if  (($min > $max))
then
    echo "min > max"    
else
    echo "min <= max"
fi

# 3  
Old 03-05-2012
Always getting what errors? Be specific. Also say what your shell is please.

$i=$i+1 is not how you do math in shell.

If you have BASH:

Code:
((i++))

If you don't:

i=`expr $i + 1` Note the spaces, not optional.
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Negative number comparison using nawk on Linux

Hi All, I am trying to compare two negative numbers using awk on linux.But it is giving me wrong result.Same code is working perfectly on solaris. print ((0+new_price) < MIN_PRICE) e.g If I try to compare -1.32(new_price) and -500(min_price) using "<" operator, output is 1 i.e true. ... (5 Replies)
Discussion started by: Rashmee
5 Replies

2. Shell Programming and Scripting

Number comparison in ksh on mac with -lt is giving wrong answer

I am trying to run following script in ksh on darwin 11.4.2: freeSpace=2469606195 spaceNeeded=200 ] && echo "no space" || echo "space available" ] && echo "no space" || echo "space available" "-lt" is giving wrong answer as "no space" Whereas '<' works fine. When I change the freespace... (4 Replies)
Discussion started by: sabitha
4 Replies

3. Red Hat

Number of CPU in LINUX server

I want to find number of CPU and number NIC card in Linux server. I have below content in /proc/cpuinfo. I have from processor 0 - 15. It means, i have 15 similar entries in that file. How many CPU we have on this server? also how do find how many NIC card on this? processor : 0... (5 Replies)
Discussion started by: govindts
5 Replies

4. UNIX for Advanced & Expert Users

Number of files currently opened in linux

Hello, How do i check number of files currently opening in the linux server? Your help is highly appreciated. Thank you ---------- Post updated at 02:43 PM ---------- Previous update was at 02:19 PM ---------- never mind!! I got it. ---------- Post updated at 02:44 PM ---------- Previous... (3 Replies)
Discussion started by: govindts
3 Replies

5. Shell Programming and Scripting

Stupid issue with number comparison

Hello all, I'm having an infuriating issue with number comparison. Basically I've written a script that runs in cygwin that SSH's to 4 servers, figures out a success percentage and if it is less than a certain point, triggers an alarm. I've managed to get it to connect to the servers, figure out... (5 Replies)
Discussion started by: DeCoTwc
5 Replies

6. UNIX for Advanced & Expert Users

Strange Number comparison issue

Hi, I am comparing two numbers, but it gives strange results: My Code: if then echo "True" else echo "False" fi This code gives False for the follwoing comparison where as True for the following: Any reason for this? Both Should have given False... I am using... (9 Replies)
Discussion started by: shihabvk
9 Replies
Login or Register to Ask a Question