How do I properly quote this bash pipeline for watch?

前端 未结 2 890
孤城傲影
孤城傲影 2021-01-20 06:37

I\'ve built up this pipeline:

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

Now I\'m trying to watch

2条回答
  •  醉酒成梦
    2021-01-20 07:07

    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"

提交回复
热议问题