简体   繁体   English

测试语句和 conky 变量

[英]test statement and conky variables

I'm trying to make a conky variable only "turn on" under certain conditions.我正在尝试使 conky 变量仅在某些条件下“打开”。 I've experimented with the test statement like in the following我已经尝试过如下所示的测试语句

${exec test -e /home/viridian/conky.conf && echo "yes" || echo "${goto 35}MOCEX : ${color}${fs_used /home/viridian/mocex}/${fs_size /home/viridian/mocex} ${alignr}${fs_used_perc /home/viridian/mocex}% ${fs_bar 4,100 /home/viridian/mocex}"}

Essentially what was supposed to happen is I place the copied conf file in the directory and it will display "yes".本质上应该发生的事情是我将复制的conf文件放在目录中,它将显示“是”。 This part works.这部分有效。 When I move it out, it will display the variable I had laid out.当我将其移出时,它将显示我布置的变量。 This doesn't work.这行不通。 Is it not possible to show a variable this way or am I doing something wrong?不能以这种方式显示变量还是我做错了什么?

The output of $exec is not parsed by conky, so you cannot use commands like $color in the echo as it will just appear as the text "$color". $exec的 output 没有被 conky 解析,因此不能在 echo 中使用$color之类的命令,因为它只会显示为文本“$color”。 In your example, you will actually see nothing as the shell is complaining about the syntax of ${fs_used /home/viridian/mocex} as it is interpreting this as variable substitution ( ${variable/pattern/replacement} ).在您的示例中,您实际上不会看到任何内容,因为 shell 抱怨${fs_used /home/viridian/mocex}的语法,因为它将其解释为变量替换( ${variable/pattern/replacement} )。 You should have used single quotes instead of double quotes.您应该使用单引号而不是双引号。

However, conky has a special command to test for file existence so you should use that, for example:但是,conky 有一个特殊的命令来测试文件是否存在,所以你应该使用它,例如:

${if_existing /home/viridian/conky.conf}  yes
${else}   ${goto 35}MOCEX : ${color}...
${endif}

This worked great, you explained it perfectly这很好用,你解释得很好

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM