如何正确引用此bash管道以供观看? [英] How do I properly quote this bash pipeline for watch?

查看:52
本文介绍了如何正确引用此bash管道以供观看?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经建立了以下管道:

I've built up this pipeline:

echo "scale=2;$(cat io | grep wchar | awk '{print $2}')/(1024^3)" | bc

现在我正在尝试watch它.我对Bash的了解确实是临时的,所以我没有成功.尝试过类似的事情:

Now I'm trying to watch it. My knowledge of Bash is really ad-hoc, and so I'm not having success. Tried things like:

watch echo "scale=2;$(cat io | grep wchar | awk '{print $2}')/(1024^3)" | bc # I understand why this fails

watch 'echo "scale=2;$(cat io | grep wchar | awk '{print $2}')/(1024^3)" | bc' # Not enough bash understanding to understand why this fails

我在做什么错了?

编辑

cat io的示例输出是

rchar: 36713294562
wchar: 36788363400
syscr: 27050
syscw: 2314540
read_bytes: 36709928960
write_bytes: 0
cancelled_write_bytes: 0

推荐答案

问题与awk的单引号有关,您可以通过转义单引号来解决它.

The problem is about the single quotes for awk, you could fix it by escaping single quotes.

watch 'echo "scale=2;$(cat io | grep wchar | awk '"'"'{print $2}'"'"')/(1024^3)" | bc'

这都是关于如何在单引号内转义单引号,有一个很好的解释

It is all about how to escaping single quotes inside single quotes, there is a good explanation "BASH, escaping single-quotes inside of single-quoted strings"

这篇关于如何正确引用此bash管道以供观看?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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