bash - 观看流程替换
问题描述
我经常运行命令
squeue -u $USER | tee >(wc -l)
Slurm 命令在哪里查看您正在运行的作业数量squeue
。这给了我输出并自动告诉我有多少行。squeue
我该怎么watch
做这个命令?
watch -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”,这意味着您可能需要使用额外的引用来获得所需的效果。
sh -c
也不支持进程替换,您在此处使用的语法为>()
.
幸运的是,您正在执行的操作实际上并不需要该语法:
watch -n.1 'out=$(squeue -u "$USER"); echo "$out"; { echo "$out" | wc -l; }'
...或者,如果你真的想使用你的原始代码,即使是在严重的性能损失(每十分之一秒开始不只是一个,而是两个sh
新的 shell - 首先,然后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
推荐阅读
- python - 将整数附加到列表中,不能将对象识别为整数
- php - PHP 将预填充表单更新到 MySQL
- c# - c#中如何获取MYSQL数据库名称、表、列和行
- javascript - AWS Signature V2:为 Javascript 中的查询请求生成签名
- r - 根据 R 中的列值复制行
- react-native - 如何更改视频的分辨率(React-Native)
- python - 如何调整每个图中标题和 x,y 轴的位置以使其适合?
- java - 为什么 leftMargin 将一半的数量添加到顶部和底部?
- php - 如何创建一个使用多行数据的表单?
- java - 如何在javafx中堆叠形状