主要有两种方法:
read -p "Input a number(0-5): " num
array=(0 1 2 3 4 5)
if [[ "${array[*]}" =~ "${num}" ]]; then
echo "You select $num"
else
echo "Invalid input!"
exit 1
fi
read -p "Input a number(0-5): " num
case $num in
[0-5])
echo "You select $num"
;;
*)
echo "Invalid input!"
exit 1
;;
esac
原文:https://www.cnblogs.com/azureology/p/13223679.html