bash读文件的写法

$ echo hengwei-2018 > a.txt
$ echo hengwei_2019 >> a.txt

# ==========1=============
$ for line in `cat a.txt`; do echo $line; done
hengwei-2018
hengwei_2019

# ==========2=============
$ while read line; do echo $line; done < a.txt
hengwei-2018
hengwei_2019

# ==========3=============
$ cat a.txt | while read line; do echo $line; done
hengwei-2018
hengwei_2019

# ==========4=============
$ for line in $(<a.txt); do echo $line; done
hengwei-2018
hengwei_2019

# ==========5=============
$ for i in `<a.txt`; do echo $i; done
hengwei-2018
hengwei_2019

 

posted @ 2020-05-26 14:15  衡子  阅读(1093)  评论(0编辑  收藏  举报