|
蓝森林 http://www.lslnet.com 2006年6月26日 11:18
管道和xargs的问题
记得原来有人说过,
“一个管道相当于一个子shell,所以必须等上一个shell执行结束(逻辑上的结束)后才能将他的输出作为子shell的输入,并启用子shell。“
那么下面这个shell
ls * | xargs -n 1 -i cat {} | head -2
结果是不是cat本目录下所有文件后才对总结果进行head -2 ?
看我的这个
bash-2.03# cat 1
1
1a1
1a1ssss
bash-2.03# cat 2
2
2a2
2a2aa
bash-2.03# cat 3
3
3a3
3a3ssss
bash-2.03# ls * | xargs -n 1 -i cat {} | head -2
1
1a1
xargs: Child killed with signal 13
这是为啥?而且结果为啥有xargs: Child killed with signal 13这个错误?
如果想每cat一个文件执行head -2 应该昨个写法? |
管道和xargs的问题
cat *|head -n2 |
管道和xargs的问题
bjgirl,结果不对啊,你可以试验试验 |
管道和xargs的问题
for file *;do cat $file|head -n2 ;done |
管道和xargs的问题
hehe,bjgirl,猜到了你要用do了,:(,
不用循环就用xargs可以么?!?!
我试着用‘ 引起来
ls | xargs -i 'cat {} | head -2',可是出错
xargs: Could not exec command: No such file or directory
xargs: Could not exec command: No such file or directory
xargs: Could not exec command: No such file or directory |
管道和xargs的问题
[code]find -name "*.txt" -exec head -n2 {} \;
[/code]
干嘛非用xargs,
[code]
find -name "*.txt"|xargs head -n2[/code] |
管道和xargs的问题
建议:你用论坛的搜索,找一下管道的概念吧 |
管道和xargs的问题
-->
呵呵,这么了解mm,
用 ls | xargs head -2 或 ls | xargs -i head -2 {}
不必cat,head一起用,多此一举。 |
管道和xargs的问题
head -2 *
btw:上面一句不能用代码标记。系统提示发贴含有非法词汇@#_#@
真搞不懂。 |
管道和xargs的问题
head -n2 *.txt
我在 freebsd 的測試是通過的... |
| |