代码:
#!/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=$' '; for line in $(cat testdata) do echo $line done IFS=${oldIFS};
文件 testdata:
abc
def
df ab cd
asas