test statement and conky variables

379 Views Asked by At

I'm trying to make a conky variable only "turn on" under certain conditions. 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". 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?

2

There are 2 best solutions below

0
On

This worked great, you explained it perfectly

0
On

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". 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}). 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:

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