Mailinglist Archive: opensuse-es (1727 mails)

< Previous Next >
Re: [suse-linux-s] Operadores Relacionales
  • From: "Sebastian Ferro" <sferro@xxxxxxxxx>
  • Date: Thu, 4 May 2006 11:11:50 -0300
  • Message-id: <2a48462e0605040711v75db5e40q46e1b5d21de7899c@xxxxxxxxxxxxxx>
El 4/05/06, Manuel A. Rodríguez<manu@xxxxxxxxxxxx> escribió:

estoy escribiendo un Script en el que tengo que evaluar si una variable
numérica esta dentro de un rango de valores...

Lo que intento hacer y no funciona es algo asi:

if [ $1 >= 1 ] && [ $1 <= 5 ]; then
echo " Valor dentro del rango 1 .. 5"
else
echo "Valor fuera del rango 1 .. 5"
fi

Lamentablemente el operador relacional ">=" o "<=" no funcionan en bash de la
manera que lo indico y no se como hacerlo.


Podrías utilizar una de las siguientes expreciones. Por cualquier cosa: man test

n1 -ne n2
True if the integers n1 and n2 are not algebrai-
cally equal.

n1 -gt n2
True if the integer n1 is algebraically greater
than the integer n2.

n1 -ge n2
True if the integer n1 is algebraically greater
than or equal to the integer n2.

n1 -lt n2
True if the integer n1 is algebraically less than
the integer n2.

n1 -le n2
True if the integer n1 is algebraically less than
or equal to the integer n2.

if [ $1 -ge 1 ]
then
echo " Valor mayor igual a 1"
else
echo " Valor menor a 1"
fi


Saludos
sf.-

< Previous Next >