« pvpgn 搭建 Battle.net 星际战网 | Main | 介绍两个盘柜存储的健康检查工具 可以用来做监控 »
June 29, 2006
shell 编程中用 read 处理用户输入
版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本声明。 https://windtear.net/archives/2006/06/29/001016.html http://windtear.net/archives/2006/06/29/001016.html shell 编程中用 read 处理用户输入 介绍一下 shell 编程中的 read 先看简单样例: read -p "Please enter your Username: " user read -s -p "Please enter your Password: " pass realpass=$(awk "/${user}/ {print \$2}" /etc/secrets) if [ "$pass" == "$realpass" ]; then # what you want to do i.e. change pass else echo "error" fi 再看简单帮助:(详细自己去man) read [-ers] [-u fd] [-t timeout] [-a aname] [-p prompt] [-n nchars] [-d delim] [name ...] -p prompt Display prompt on standard error, without a trailing new- line, before attempting to read any input. The prompt is displayed only if input is coming from a terminal. -s Silent mode. If input is coming from a terminal, charac- ters are not echoed. 所以前面的样例就很容易理解了 |
Posted by windtear at June 29, 2006 11:54 PM