judge_yes_no.sh

#!/bin/bash

read -p "Are you sure?[y/n]:" sure
case $sure in
 y|Y|yes|Yes|YES)
   echo "you enter $sure"
   ;;
 n|N|no|No|NO)
   echo "you enter $sure"
   ;;
 *)
   echo "error"
   ;;
esac

验证:

[root@logstash ~]# sh judge_yes_no.sh 
Are you sure?[y/n]:d
error
[root@logstash ~]# sh judge_yes_no.sh 
Are you sure?[y/n]:y
you enter y
[root@logstash ~]# sh judge_yes_no.sh 
Are you sure?[y/n]:Y
you enter Y
[root@logstash ~]# sh judge_yes_no.sh 
Are you sure?[y/n]:yes
you enter yes
[root@logstash ~]# sh judge_yes_no.sh 
Are you sure?[y/n]:Yes
you enter Yes
[root@logstash ~]# sh judge_yes_no.sh 
Are you sure?[y/n]:n
you enter n
[root@logstash ~]# sh judge_yes_no.sh 
Are you sure?[y/n]:N
you enter N
[root@logstash ~]# sh judge_yes_no.sh 
Are you sure?[y/n]:No
you enter No
[root@logstash ~]# sh judge_yes_no.sh 
Are you sure?[y/n]:NO
you enter NO
[root@logstash ~]#