优化脚本,使用fi else条件语法
[root@centos7-kevin306 ~]# cat yesorno_if.sh #!/bin/bash # #******************************************************************** #Author: Kevin Ma #QQ: 1065015188 #Date: 2021-04-05 #FileName: yesorno_if.sh #URL: www.kevin306.cn #Description: The test script #Copyright (C): 2021 All rights reserved #******************************************************************** read -p "Are you OK (yes/no)? " answer if [[ $answer =~ ^([Yy]|[Yy][Ee][Ss])$ ]] ;then echo "YES" elif [[ $answer =~ ^([Nn]|[Nn][Oo])$ ]];then echo "No" else echo "Input false,please input yes or no !" fi
查看并验证结果:
测试OK