【发布时间】:2013-06-10 14:14:54
【问题描述】:
我有一个包含如下内容的文本文件:
abc 123, comma
the quick brown fox
jumped over the lazy dog
comma, comma
我写了一个脚本
for i in `cat file`
do
echo $i
done
由于某种原因,脚本的输出不会逐行输出文件,而是在逗号和换行符处将其断开。为什么 cat 或 "for blah in cat xyz" 这样做,我怎样才能让它不这样做?我知道我可以使用
while read line
do
blah balh blah
done < file
但我想知道为什么 cat 或“for blah in”这样做是为了加深我对 unix 命令的理解。 Cat 的手册页对我没有帮助,在 bash 手册中查找或循环也没有得到任何答案(http://www.gnu.org/software/bash/manual/bashref.html)。提前感谢您的帮助。
【问题讨论】: