观看过程替换 [英] Watch with Process Substitution

查看:61
本文介绍了观看过程替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常运行命令

squeue -u $USER | tee >(wc -l)

其中 squeue Slurm命令您正在运行的作业.这既给了我 squeue 的输出,又自动告诉了其中有多少行.

where squeue is a Slurm command to see how many jobs you are running. This gives me both the output from squeue and automatically tells how many lines are in it.

如何监视此命令?

监视-n.1"squeue -u $ USER | tee>(wc -l)" 导致

Every 0.1s: squeue -u randoms | tee >(wc -l)                                                                                                                                                                                                                                                                                                        Wed May  9 14:46:36 2018

sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `squeue -u randoms | tee >(wc -l)'

推荐答案

watch 手册页中:

请注意,命令已分配给"sh -c",这意味着您可能需要使用额外的引号才能获得所需的效果.

Note that command is given to "sh -c" which means that you may need to use extra quoting to get the desired effect.

sh -c 也不支持进程替换,此处使用的语法为>().

sh -c also does not support process substitution, the syntax you're using here as >().

幸运的是,您所做的事情实际上并不需要该语法:

Fortunately, that syntax isn't actually needed for what you're doing:

watch -n.1 'out=$(squeue -u "$USER"); echo "$out"; { echo "$out" | wc -l; }'

...或者,如果您真的想要使用原始代码,即使性能损失很大(每十个十分之一都启动一个新的shell,而不是两个 新壳)第二个-首先是 sh ,然后是 bash ):

...or, if you really want to use your original code even at a heavy performance penalty (starting not just one but two new shells every tenth of a second -- first sh, and then bash):

bash_cmd() { squeue -u "$USER" | tee >(wc -l); } # create a function
export -f bash_cmd            # export function to the environment
watch -n.1 'bash -c bash_cmd' # call function from bash started from sh started by watch

这篇关于观看过程替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆