博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
shell脚本read -t 超时输入测试
阅读量:7164 次
发布时间:2019-06-29

本文共 709 字,大约阅读时间需要 2 分钟。

[root@server0 shellStudy]# cat timeout.sh #!/bin/bashTIMEOUT=3 #超时间隔echo "What is your name?"echo "Quickly now, you only have $ITMEOUT secconds to answare!"read nameif [ -z "$name" ]  #未输入任何值then        name="(no answare)"fiecho "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"fiexit 0[root@server0 shellStudy]# ./timeout.sh What is your name?Quickly now, you only have  secconds to answare!ruskyyour name is rusky.input your age,you only have 3 seconds:20you age is 20[root@server0 shellStudy]#

  

转载于:https://www.cnblogs.com/rusking/p/8550044.html

你可能感兴趣的文章