bash linux 使用 watch 命令进行多次调用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29119115/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
linux use watch command with multiple calls
提问by sjas
How can I combine two (or more) calls by the watch
command?
Such that they are run together (serially) and watch
shows their combined output?
如何通过watch
命令组合两个(或多个)调用?
这样它们一起(串行)运行并watch
显示它们的组合输出?
I.e. watch command1 command2
IE watch command1 command2
So to show the contents of two different directories:
所以要显示两个不同目录的内容:
watch $(ls dir1) $(ls dir2)
(The subshell parens were just added for clarity.)
(为了清楚起见,刚刚添加了子外壳括号。)
Of course I could create a script to run both commands, pipe the results into a tempfile and cat it for its contents periodically through watch, but I'd refrain from it if this is natively possible somehow. :)
当然,我可以创建一个脚本来运行这两个命令,将结果通过管道传输到一个临时文件中,并通过 watch 定期将其内容分类,但如果这本身就可能以某种方式实现,我会避免这样做。:)
Subshells, grouping, process substitution did not help me, so I am out of luck and have no idea where to look now.
子外壳、分组、进程替换对我没有帮助,所以我很不走运,现在不知道去哪里找。
Is this possible at all?
这可能吗?
UPDATE:
更新:
watch cat <(ls dir1) <(ls dir2)
gives me on the first iteration what I'd love to see refreshed periodically, but not repeatedly. :(
在第一次迭代时给了我我希望看到的定期刷新,但不是重复刷新。:(
回答by StenSoft
watch
by default runs the passed command in shell so you can pass it any command valid for shell:
watch
默认情况下,在 shell 中运行传递的命令,因此您可以将任何对 shell 有效的命令传递给它:
watch 'ls dir1; ls dir2'