Hi,
I have this case statement for which the options change depending on the number of subdirectories in a directory.
However, lets say there happen to be 15 subdirectories. This causes the case statement to echo "Invalid choice" if the user enters any values except or 1 and 5, similarly if there are 18 directories it echos "invalid choice" if the user enters any values except for 1 and 8 etc etc.
How can I stop this happening and get it to echo the choice for the range 1-14 or 1-18 etc?
Here's the code:
---------------------------------------------------------------
echo "Choose the client"
CLIENTS=`ls /support/patches`
I=0;
for client in $CLIENTS
do
I=`expr $I + 1`
echo "$I) $client"
done
while true
do
read ANS
echo $ANS
case $ANS in
[1-$I]) echo "Choose option $ANS
break
;;
*) echo "Invalid choice, please enter a valid choice"
;;
esac
done
-----
cheers
Rob
I have this case statement for which the options change depending on the number of subdirectories in a directory.
However, lets say there happen to be 15 subdirectories. This causes the case statement to echo "Invalid choice" if the user enters any values except or 1 and 5, similarly if there are 18 directories it echos "invalid choice" if the user enters any values except for 1 and 8 etc etc.
How can I stop this happening and get it to echo the choice for the range 1-14 or 1-18 etc?
Here's the code:
---------------------------------------------------------------
echo "Choose the client"
CLIENTS=`ls /support/patches`
I=0;
for client in $CLIENTS
do
I=`expr $I + 1`
echo "$I) $client"
done
while true
do
read ANS
echo $ANS
case $ANS in
[1-$I]) echo "Choose option $ANS
break
;;
*) echo "Invalid choice, please enter a valid choice"
;;
esac
done
-----
cheers
Rob