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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 12:33:23  来源:igfitidea点击:

linux use watch command with multiple calls

linuxbashshellwatch

提问by sjas

How can I combine two (or more) calls by the watchcommand?
Such that they are run together (serially) and watchshows 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

watchby 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'