Jeremy Mates wrote:
On 2026-04-16 06:21:17 +0200, Harald Dunkel wrote:
        gate5b# x=$(rcctl ls failed) || rcctl restart $x
        smtpd(ok)
        gate5b# rcctl ls failed
        gate5b# echo $?
        0

This is confusing. Imagine grep would exit 1 if it has found
something.

grep uses inverse logic (positive match) to `rcctl ls failed` (negative
match) so may not be the best analogy. One may want to do something like

   rcctl ls failed || mail ...

to notify from a script but only when there is something to do, that is,
when there is a failed service and therefore a non-zero exit status word
to indicate that.


This is bad code. IMHO

        rcctl ls failed && echo 'service is not running'

should work similar to

        rcctl ls failed | grep -q smtpd && echo 'smtpd is not running'

but it doesn't. I understand that the exit value of "rcctl ls failed"
is inverted to grep; thats the problem.


Regards
Harri

Reply via email to