Quote:
Originally Posted by chrism01
Code:
if [[ "$RES" =~ 1$ ]]
then
echo "match 1"
fi
if [[ "$RES" =~ 10$ ]]
then
echo "match 10"
fi
Regexes match the target string anywhere; you need to anchor the end ($)
|
Hi Chris
For some reason this didnt work for me however i found that the below while loop worked after playing around a few time
while [[ ! "$RES" =~ ^(1[0-1]|[1-9x])$ ]]
Thanks for your help though
---------- Post added 05-13-15 at 12:01 PM ----------
Quote:
Originally Posted by millgates
How about using case?
Code:
while :; do
read -p "Please select an above option : " res
case "$res" in
1) echo "Option 1 Selected" ;;
2) echo "Option 2 Selected" ;;
# ...
10) echo "Option 10 Selected" ;;
*) break ;;
esac
done
|
I actually slapped my head after reading this as not sure why i didnt use a case statement in the first place