while read line

测试用到的text文件

1111111111111111111111111111111111111111111
2222222222222222222222222222222222222222222
3333333333333333333333333333333333333333333
6666666666666666666666666666666666666666666
7777777777777777777777777777777777777777777
8888888888888888888888888888888888888888888

示例

#!/bin/bash
count=1 # 赋值语句,不加空格
cat text | while read line; do # cat 命令的输出作为read命令的输入,read读到>的值放在line中
    echo "Line $count:$line"
    count=$(($count + 1)) # 注意中括号中的空格。
done
echo "finish"
exit 0
#!/bin/bash
while read line; do
    echo $line
done <./text #<A写在最后相当于给整个while do 语句加了一个约束条件,读取文件A里每行至文件尾结束

 

posted @ 2021-07-05 17:37  Bonnie_ξ  阅读(228)  评论(0)    收藏  举报