linux-tutorial/codes/shell/示例脚本/输入和输出/超时和输入计数.sh
2019-10-10 08:56:31 +08:00

24 lines
496 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
# timing the data entry
if read -t 5 -p "Please enter your name:" name
then
echo "Hello, $name, welcome to my script"
else
#起到换行的作用
echo
#输入计数 -n1
read -n1 -p "Do you want to continue [Y/N]?" answer
case $answer in
Y | y) echo
echo "Fine, continue on..." ;;
N | n) echo
echo "OKgoodbye" ;;
*) echo
echo "OK, wrong, goodbye"
esac
echo "Sorry, this is the end of the script"
fi