Files
shell-scripts/功能脚本/基础脚本/参数传递-提示确认.sh
2023-05-15 16:49:09 +08:00

45 lines
796 B
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
## 确认提示(一次)
# 这个示例代码将为确认提示一次如果你给输入错误程序会以状态1退出。
# 这个例子将只接受Y或N或YES或NO不区分大小写
read -r -p "Are You Sure? [Y/n] " input
case $input in
[yY][eE][sS]|[yY])
echo "Yes"
;;
[nN][oO]|[nN])
echo "No"
;;
*)
echo "Invalid input..."
exit 1
;;
esac
## 确认提示(循环确认)
# 提示进行确认(输入正常退出,输入错误则需重新输入,知道输入正确才可以)
while true
do
read -r -p "Are You Sure? [Y/n] " input
case $input in
[yY][eE][sS]|[yY])
echo "Yes"
break
;;
[nN][oO]|[nN])
echo "No"
break
;;
*)
echo "Invalid input..."
;;
esac
done