码迷,mamicode.com
首页 > 其他好文 > 详细

read命令

时间:2015-08-11 23:38:20      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:read

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命令

标签:read

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!