Linux/Unix Shell Scripting - optimizar bucle until en el que hay elegir entre un rango de numeros

 
Vista:

optimizar bucle until en el que hay elegir entre un rango de numeros

Publicado por TuXedo (4 intervenciones) el 10/12/2016 12:51:37
Mi pregunta es como podría optimizar los bluces until en los que tengo que elegir entre los rangos numéricos para que no quede en una linea tan larga.

1
until [ "$IDEN" = '1' ] || [ "$IDEN" = '2' ] || [ "$IDEN" = '3' ] || [ "$IDEN" = '4' ] || [ "$IDEN" = '5' ] || [ "$IDEN" = '6' ] || [ "$IDEN" = '7' ] || [ "$IDEN" = '8' ] || [ "$IDEN" = '9' ] || [ "$IDEN" = '10' ]


El código que uso es el siguiente y está funcionando pero me gustaría que quedara mejor optimizado.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
until [ "$ENTORNO" = 'entorno1'] || [ "$ENTORNO" = 'entorno2']
do
echo "elige una opcion valida 'entorno1'/'entorno2'"
read ENTORNO
done
 
echo "Introduce el numero identificador del proceso que quieres arrancar"
read IDEN
if [ "$ENTORNO" = 'entorno1' ]
then
	until [ "$IDEN" = '1' ] || [ "$IDEN" = '2' ] || [ "$IDEN" = '3' ] || [ "$IDEN" = '4' ] || [ "$IDEN" = '5' ] || [ "$IDEN" = '6' ] || [ "$IDEN" = '7' ] || [ "$IDEN" = '8' ] || [ "$IDEN" = '9' ] || [ "$IDEN" = '10' ]
	do
		echo "Introduce un numero de identificador valido (1..10)"
		read IDEN
	done
	script_arranque $IDEN
elif [ "$ENTORNO" = 'entorno2' ]
then
	until [ "$IDEN" = '1' ] || [ "$IDEN" = '2' ] || [ "$IDEN" = '3' ] || [ "$IDEN" = '4' ] || [ "$IDEN" = '5' ]
	do
		echo "Introduce un numero de identificador valido (1..5)"
		read IDEN
	done
	script_arranque $IDEN
fi


Gracias!!
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

optimizar bucle until en el que hay elegir entre un rango de numeros

Publicado por tom (361 intervenciones) el 10/12/2016 19:54:17
¿
1
[ $IDEN -ge 1 -a $IDEN -le 9 ]
?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar

optimizar bucle until en el que hay elegir entre un rango de numeros

Publicado por TuXedo (4 intervenciones) el 11/12/2016 07:56:05
Gracias, funciona perfectamente.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar