在“for”循环中使用“tee”进行管道传输
这可能是新手逃避问题。我正在尝试在这样的 for 循环中运行命令
$ for SET in `ls ../../mybook/WS/wsc_production/`; do ~/sandbox/scripts/ftype-switch/typesort.pl /media/mybook/WS/wsc_production/$SET ./wsc_sorter/$SET | tee -a sorter.log; done;
,但最终 sorter.log
为空。 (我确信有一些输出。)如果我转义管道符号 (\|
),我最终不会得到 sorter.log
完全没有。
我做错了什么?
$ bash --version
GNU bash, version 4.1.5(1)-release (i486-pc-linux-gnu)
编辑:糟糕,/media/mybook/睡着了,所以实际上没有输出。该代码首先是正确的。不过还是谢谢大家的评论。
This is probably a newbie's escaping problem. I'm trying run command in a for loop like this
$ for SET in `ls ../../mybook/WS/wsc_production/`; do ~/sandbox/scripts/ftype-switch/typesort.pl /media/mybook/WS/wsc_production/$SET ./wsc_sorter/$SET | tee -a sorter.log; done;
but I end up with sorter.log
being empty. (I'm sure there is some output.) If I escape the pipe symbol (\|
), I end up with no sorter.log
at all.
What am I doing wrong?
$ bash --version
GNU bash, version 4.1.5(1)-release (i486-pc-linux-gnu)
Edit: Oops, /media/mybook/ fell asleep, so there actually was no output. The code was correct in the first place. Thanks to all for comments, though.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
格伦说得好。我想提供一个不同的角度:您可以将“tee”命令移到 for 循环之外。这种方法的优点是 tee 仅被调用一次:
Glenn said it well. I would like to offer a different angle: you can move the 'tee' command outside of the for loop. The advantage to this approach is tee is invoked only once:
您正在使用
tee
,因此如果有输出,您会在终端上看到它。你看到了什么?如果您看到输出,则您看到的可能是 stderr,因此您可能需要重定向它:
You're using
tee
, so if there is output, you'd see it on your terminal. What do you see?If you see output, it's probably stderr you're seeing, so you might want to redirect it:
我最深切的歉意,问题出在其他地方,我的脚本实际上根本没有输出任何内容。现在可以了。
我产生了问题在于转义的错觉的两个原因:
好吧,这是我在知识之路上遇到的一些绊脚石......:)
My deepest apologies, the problem was somewhere else and my script actually did not output anything at all. Now it works.
Two reasons why I got the illusion that the problem is in escaping:
Well, that's for some stumbling on my way to knowledge... :)