首页 > 其他 > 详细

read命令

时间:2015-08-11 23:37:41      阅读:287      评论:0      收藏:0      [点我收藏+]

read [-ers] [-a aname] [-d delim] [-i text] [-n nchars] [-N nchars] [-p prompt]        [-t timeout] [-u fd] [name ...]

If no names are supplied, the line read is assigned to the variable REPLY.


-r     Backslash does not act as an escape character.  The backslash is considered to  be  part  of  the line.  In particular, a backslash-newline pair may not be used as a line continuation.


每次调用read命令都会读取文件中的"一行"文本。当文件没有可读的行时,read命令将以非零状态退出。读取文件的关键是如何将文本中的数据传送给read命令。最常用的方法是对文件使用cat命令并通过管道将结果直接传送给包含read命令的while命令 。

#!/bin/bash 
count=1
cat dat| while read line        #cat 命令的输出作为read命令的输入,read读到的值放在line中 
do 
   echo "$count:$line" 
   count=$(($count + 1))
done
exit 0


read命令

原文:http://chomper.blog.51cto.com/7866214/1683825

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!