On Wednesday, October 8, 2014, 6:31:08 PM, Martin confabulated:

> On Wed, 2014-10-08 at 16:46 -0600, Amir Caspi wrote:
>> On Oct 8, 2014, at 4:23 PM, Duane Hill <duih...@gmail.com> wrote:
>> > 
>> > No.  &&  is  a  way  of chaining commands together. Your cron says run 
>> > sa-update  and  then  restart  spamd.  In  other words, when sa-update 
>> > finishes  running,  regardless  if there was an update applied or not, 
>> > restart spamd.
>> 
>> Unless I am mistaken, I believe this is not correct. On *nix systems,
>> && is the logical "and" operator, and it can be used to chain commands
>> as dependencies. 
>>
> Correct.

>> && short-circuits on failure, so if the first command returns zero,
>> the "and" would fail and the second command never runs. The second
>> command is only evaluated if the first returns non-zero ("true").
>>
> Incorrect. sh and its descendants such as bash and ksh reverse the
> representation of true and false with respect to C and its descendants:
> in shell scripts a value of zero is TRUE and non-zero is FALSE. 

> This is a necessary feature since, by convention, under UNIX/Linux or
> any other POSIX-compliant OS a program returns zero on success and a
> non-zero value on failure. The non zero exit code *may* be a value
> showing what the error was but this isn't guaranteed: all you can say is
> that a non-zero exit code indicates that the program didn't complete its
> usual activity.

>>  Hence, spamd is restarted only if sa-update actually loads an update,
>> and not otherwise.
>> 
> Correct: "a && b" in a shell script means run b iff a was successful

>> This is the same reason why you can also see commands like:
>> do_this || die
>> in perl scripts, because the logical "or" operator || will
>> short-circuit on success, hence the "fallback" command never gets run
>> if the first one succeeded.
>> 
> True, but be aware that Perl, like C, C++, Java,.... represents false by
> zero and true by non-zero values - the reverse of a Unix/Linux/POSIX
> shell script.

> In all cases there's no danger of confusion as long as you write logical
> statements that are either boolean algebra that makes no attempt to
> represent the value of a logical variable or only represents it by the
> literals TRUE and FALSE.

Thanks for clarifying everything. So, if I had:

  /usr/local/bin/sa-update && /usr/local/bin/sa-compile && 
/usr/local/etc/rc.d/sa-spamd restart

the  only time spamd would restart is if sa-update AND sa-compile were
successfully completed, correct?

-- 
Duane Hill
duih...@gmail.com
"If at first you don't succeed, so much for sky diving."

Reply via email to