while loop problem

#!/bin/sh

clear

befehle=( whoami ls who finger ps )
eingabe=5

while [ $eingabe > 4 ]
do
 # for i in 0 1 2 3 4
  #  do
   #   echo  $i - ${befehle[$i]}
  #done
echo "you're still in the loop"
read eingabe
echo "Input:" $eingabe
done

Hello,

I am having a problem with this loop. WHATEVER I give in as an input, it does not exit the loop :s

#!/bin/sh

clear

befehle="\( whoami ls who finger ps \)"
eingabe=5

while [ "$eingabe" > 4 ]
do
 # for i in 0 1 2 3 4
  #  do
   #   echo  $i - ${befehle[$i]}
  #done
echo "you're still in the loop"
read eingabe
echo "Input:" $eingabe
done
while [ $eingabe -gt 4 ]

Problem solved, thanks.

I had to use the -gt instead of >

Sorry, your error wasnt clear to me...
And testing again I realized what you wanted and you got the answer before I had time to correct... yes it was -gt like this:

while [ "$eingabe" -gt 4 ]

Hi vbe,

I never understood the use of "" with this kind of numerical comparison.
If eingabe="" then without them you will get:

[: -gt: unary operator expected

but with these double quotes you will get:

[: : integer expression expected

So it seems to me one might as well leave them out, no?

while [ $eingabe -gt 4 ]

Greetings scrutinizer,
I suppose its a habit from the time HPUX had a shell that was very fussy on syntax especially in tests for my part...

You had to write:

if test -x "$1"
then
..
if [ "$ANSWER" = y ]
then
...
if [ "$SZ" -le  5000 ]
then
.
.

All the best

The trick is to quote both parts of the relation:

while [ "$var" = "somevalue" ] ; do
...

while [ "$var" = "5" ] ; do
...

This way you force the shell to do a string comparison, regardless of what content is stored in "$var".

bakunin

Hi bakunin,

Ok, but we can't use a string comparison here, we have to use a numerical comparison.

S.