Click to See Complete Forum and Search --> : expr and test question.. easy


morphman
06-10-2002, 01:57 PM
Ok, ive been working my way around this for a while now but not i just plain need to learn this. How do i do something like this:
while integer1 < integer 2
do
commands
done

Do i use test or expr? Lets say i read values into two variables "var1" and "var2". How do it compare them in a while statement to see if one is lower than the other? Perhaps someone can give me an examle of the exact syntax? The stinking man pages for test, expr, and while havent helped me at all. Thanks!

--Morphman

dchidelf
06-10-2002, 07:10 PM
This is ksh, should be close for bourne shells

while [ $var1 -lt $var2 ]
do
# stuff to do
done

which is equivalent to

while test $var1 -lt $var2
do
# stuff
done

[ 10 June 2002: Message edited by: dchidelf ]

morphman
06-11-2002, 03:45 PM
ive been trying:
while [ test $var1 -le $var2 ]
perhaps i dont need the "test" in there? ill try that out. Thanks!

--Morphman

bwkaz
06-12-2002, 12:42 PM
Originally posted by morphman:
<STRONG>ive been trying:
while [ test $var1 -le $var2 ]
perhaps i dont need the "test" in there? ill try that out. Thanks!</STRONG>

The [ executable (it is an executable -- or at least a link to one -- look in /usr/bin! :eek: ) is a symlink to test.

But then, too, bash interprets the [ as an "alias", sort of, for test anyway.

So no, you don't need test.