proxy代理   soft软件   IT 业界特快   norton 诺顿病毒库   代理列表   search FTP搜索   whois IP地理位置   blog 追求完美  
money理财   life生活   RSS聚合门户   firefox WEB浏览器   免费域名   typeset 假古文   AntiVirus 反病毒   ipcn 站点导航  

« 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.

所以前面的样例就很容易理解了
本blog WWW

Posted by windtear at June 29, 2006 11:54 PM

本站使用中的任何问题,请与 windtear @ windtear.net 联系
Copyright© 1999-2024 Windtear. All rights reserved.