linux shell 读取文件脚本

逐行读取文本文件的几种方法:
shell中有没有类似 于open的命令??
也就是用shell能不能打开文件获得句柄呢??

1.用read读取文件重定向
#! /bin/bash

while read line
do
echo $line
done < filename
2.使用管道
cat filename |while read line
do
echo \$line
done

3.使用for in
for line in $(cat filename)
do
echo $line

还有种使用文件描述符的方法,关于文件描述符我还不太懂
0 stdin
1 stdout
2 stderr

我只理解这几个常用的
2>/dev/null
1>/dev/null
2>&1
1>&2

posted @ 2022-03-06 10:40  叶常落  阅读(523)  评论(0编辑  收藏  举报