0

Can this be explained :

[ ! -f /var/run/nginx.pid ] || kill -USR1 `cat /var/run/nginx.pid`

(the content of /etc/logrotate.d/nginx) ?

Why is this not as

[ -f /var/run/nginx.pid ] && kill -USR1 `cat /var/run/nginx.pid`

because should we not be sending the signal only if nginx.pid file exists ? if pid won't exist, then nginx is not running and we cannot send a signal to the master process ?

Vishnu
  • 479
  • 1
  • 3
  • 14

1 Answers1

1

Both statements perform the same function but have different exit codes.

[ ! condition ] || action
[ condition ] && action

Both statements perform action only if condition is true. The only alternative is to not perform the action when the condition is false.

If condition is true the exit code of the entire statement is the exit code of the action.

It is when the condition if false that the exit code of the two statements differ, because it is the exit code of the [ ... ] element.

Richard Smith
  • 45,711
  • 6
  • 82
  • 81