首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

cat跟echo疑问

2012-08-30 
cat和echo疑问写了个小脚本如下:Python code#!/bin/bashphrase_file/home/hadoop/phrases.txtfor content

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

Python code
#!/bin/bashphrase_file=/home/hadoop/phrases.txtfor 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就解决了,不过这两者有什么区别呢?

热点排行