shell腳本read -t 超時輸入測試


[root@server0 shellStudy]# cat timeout.sh 
#!/bin/bash
TIMEOUT=3 #超時間隔
echo "What is your name?"
echo "Quickly now, you only have $ITMEOUT secconds to answare!"
read name
if [ -z "$name" ]  #未輸入任何值
then
        name="(no answare)"
fi

echo "your name is $name."

echo "input your age,you only have 3 seconds:"
read -t $TIMEOUT age  #使用-t 參數,限制輸入時長

if [ -z "$age" ]   #未輸入任何值
then
        echo "you didnt input anything!"
else
        echo "you age is $age"
fi
exit 0
[root@server0 shellStudy]# ./timeout.sh 
What is your name?
Quickly now, you only have  secconds to answare!
rusky
your name is rusky.
input your age,you only have 3 seconds:
20
you age is 20
[root@server0 shellStudy]# 

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM