1.示例代码如下
#!/bin/bash declare -a serial serial=(1 2 3 4) PS3="Enter a number: " select var in "a" "b" "c" "d" do if ! echo ${serial[@]} | grep -q $REPLY; then echo "please enter [1-4]." continue fi echo "your anwser is: $var" break done2.运行结果如下所示:
[root@localhost ~]# bash test.sh 1) a 2) b 3) c 4) d Enter a number: 5 please enter [1-4]. Enter a number: 3 your anwser is: c [root@localhost ~]#