日期:2014-05-16  浏览次数:20625 次

cat和echo疑问
写了个小脚本如下:
Python code

#!/bin/bash

phrase_file=/home/hadoop/phrases.txt

for content in `cat ${phrase_file}`
do
        phrase=`[b][color=#FF0000]cat ${content}[/color][/b]| awk 'BEGIN{FS=";"}{print $1}'`
done


phrases.txt文件格式如下:
A previous rep told me;1280

照理说代码是ok的,但调试结果是这样:
+ for content in '`cat ${phrase_file}`'
++ cat A
++ awk 'BEGIN{FS=";"}{print $2}'

我估计红色粗体地方的问题,我试图用phrase=`echo ${content} | awk 'BEGIN{FS=";"}{print $1}'`来解决,结果不行.phrase=`> ${content} | awk 'BEGIN{FS=";"}{print $1}'`也不行,请问是怎么回事呢?

------解决方案--------------------
哪里有echo的事情
------解决方案--------------------
cat是打印文件,你cat $content是干嘛?

用echo
------解决方案--------------------
探讨

把for content in `cat ${phrase_file}`改为 `cat ${phrase_file}` | while read content就解决了,不过这两者有什么区别呢?