read 计时命令
2015-09-08 10:59
211 查看
使用read命令存在潜在危险,脚本很可能会停下来一直等待脚本用户输入数据,如果无论是否输入数据脚本的必须继续执行,那么可以使用-t选项指定一个计时器。-t选项指定read命令等待输入的秒数,当计数器计时数满时,read命令返回一个非零退出状态
文件名 test25.sh
运行 sh test25.sh
出现 Please enter your name:
输入admin,出现 Hello admin,welcome to my script
如果等待5s不输入后出现 Sorry,too slow!
文件名 test25.sh
#!/bin/bash # timing the date entry if read -t 5 "Please enter your name: " name then echo " Hello $name,welcome to my script" else echo echo "Sorry,too slow!" fi
运行 sh test25.sh
出现 Please enter your name:
输入admin,出现 Hello admin,welcome to my script
如果等待5s不输入后出现 Sorry,too slow!
相关文章推荐
- flex 圆形布局
- Delete Node in a Linked List
- Servlet异常处理
- 比较好的 Python decorator 介绍
- 配置OpenGrok查看源码
- linux日志读写接口函数
- [译]2015年web开发需要注意的事
- maven 相关错误解决
- CString/string 区别及其转化
- TCP/IP网络编程 学习笔记_15 --多播与广播
- TCP/IP网络编程 学习笔记_15 --多播与广播
- 减少C++代码编译时间的方法
- Js/Jquery获取iframe中的元素 在Iframe中获取父窗体的元素方法
- Bidirectional @OneToMany / @ManyToOne association
- Android工具代码
- C语言函数调用模型[调用过程中在堆栈中的出栈、进栈顺序]
- [MDB] IMP 导入MDB
- Python单元测试框架
- Fix Internet Explorer Crashes with SharePoint 2013 Online Presence Indicators
- win10不能召唤小冰打不开怎么办?