select 语句是一个类似于for 的语句,不过可以更好的实现交互
脚本如下,仅供参考
#!/bin/bash
PS3="Select a number:"
while true;do
select mysql_version in 5.6 5.7 quit;do
case $mysql_version in
5.1)
echo "mysql 5.1"
break
;;
5.6)
echo "mysql 5.6"
break
;;
quit)
exit
;;
*)
echo "Input error,Please enter again!"
break
esac
done
done
输出:
[root@rocos ~]# bash t.sh
1) 5.6
2) 5.7
3) quit
Select a number:1
mysql 5.6
1) 5.6
2) 5.7
3) quit
Select a number:1
mysql 5.6
1) 5.6
2) 5.7
3) quit
Select a number:2
Input error,Please enter again!
1) 5.6
2) 5.7
3) quit
Select a number:3