xiuxuan 发表于 2018-8-26 13:56:26

shell读文件的四种方法

# cat read_line.sh  
#!/bin/bash
  
for i in `cat file.txt`
  
do
  
    echo $i
  
done
  

  
while read line
  
do
  
    echo $line
  
done < file.txt
  

  
cat file.txt | while read line
  
do
  
    echo $line
  
done
  
此种方法和第二种会有所不同,第三种方法会产生三种shell,第一个是cat,第二个是管道,第三种是while
  

  
exec > ./a.txt
  
while read line
  
do
  
    echo $line
  
done


kdxcne 发表于 2018-8-26 21:47:28

谢谢分享
页: [1]
查看完整版本: shell读文件的四种方法