is there any way to check or test the input from a 'read' against a for 'loop'?
I don't want the case statement to execute there any of the input is incorrect. As of right now it will loop through, outputting the * ) branch multiple times while still executing the correct inputs.
Example:
echo "Select Your Options (Seperated by spaces): 1 2 3"
read SELECTION
# Test SELECTION here? Then exit if fail? IE, if a 4 is entered.
for INPUT in $SELECTION; do
case $INPUT in
1 ) echo "you selection option 1"
;;
2 ) echo "you selection option 2"
;;
3 ) echo "you selection option 3"
;;
* ) echo "Check your selection. Anything outside the following will make this fail: 1 2 3 "
RETVAL=1
exit
;;
esac
done
select
bash construct; it takes care of presenting numeric options for you. – dhag Dec 17 '15 at 19:51ksh
construct. – mikeserv Dec 17 '15 at 20:15bash
borrowed (I assume) theselect
statement a very long time ago; it's present inbash
2.0 at least. – chepner Dec 17 '15 at 22:52