shell-逐行读取文件
代码:
#!/bin/bash echo 方法1 while read line do echo $line; done < testdata echo "" echo 方法2 cat testdata | while read line do echo $line done echo "" echo 方法3 oldIFS=${IFS}; IFS=$'\n'; for line in $(cat testdata) do echo $line done IFS=${oldIFS};
文件 testdata:
abc
def
df ab cd
asas