0
I think this is due to an optimisation done by the shell. Your code will eventually run
sh -c 'cat /proc/$$/comm'
and the shell will expand the $$
to the shell's pid, then decide that since there are no more commands to do, it will exec()
the cat
rather than forking to exec and waiting for the child.
You can see this if you run the above command, which replies cat
. But if you add another command, eg
sh -c 'cat /proc/$$/comm; echo $$'
you will see sh
and the second command. A quick fix is to use <
to make the shell open the proc file before running cat:
'${execi 3600 cat </proc/$$/comm}'
If you want to see the difference, use strace -f -o /tmp/trace sh -c '...'
and look through the trace output.
Unfortunately, conky will alway run commands using sh
rather than any SHELL
value you may have set in the environment. So you will always find sh
unless it is a link to some other shell, such as bash
. The easy answer is to:
${execi 3600 echo $SHELL}
or if you need to really execute the shell then:
${execi 3600 exec $SHELL -c 'cat /proc/$$/comm;echo -n'}
Using
cat < /proc/$$/comm
will printsh
, but my shell iszsh
. – Amir A. Shabani – 2019-09-11T12:27:13.667It seems conky always runs sh. See my update. – meuh – 2019-09-11T13:35:15.463
This works, but I can manually change the value of
$SHELL
, for example likeSHELL="bash"
, to something else and the behavior changes. So I guess it doesn't differ from using$(execi 3600 echo $SHELL)
. – Amir A. Shabani – 2019-09-11T14:20:24.700