标签: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
原文地址:http://chomper.blog.51cto.com/7866214/1683825