1

我尝试使用 ${if_existing ..} 来检查文件是否存在于 conky 中,如下所示:

    ${if_existing /home/stanislav/.cache/yandexweather/bkn_n.png}YES \
    ${else}NO
    ${endif}\

这非常有效。但是,如何将 ${if_existing ..} 语句与另一个命令的输出一起使用?例如:

    ${if_existing echo "~/.cache/yandexweather/"$(python ~/.cache/yandexweather/yw_script.py -image_0)}YES \
    ${else}NO
    ${endif}\

后者不起作用

4

1 回答 1

1

您可以使用${eval ...}先计算 shell 命令,然后${if_...}解析部分。例如,

${eval $${if_existing ${execi 10 echo "myfile"}}\
          YES $${else} NO $${endif} }

在 eval 内部,if.. elseandendif部分通过将 to 加倍而无法$工作$$。但是,该${execi部件每 10 秒运行并执行一次 shell 命令 ( echo ...)(如果您的表达式永远不会改变,请选择一个较大的值)。

在执行程序返回字符串(myfile在本例中为 )后,将再次解析生成的命令。每个$$都被评估为$,所以我们有:

${if_existing myfile} YES ${else} NO ${endif}
于 2019-08-13T13:11:17.600 回答