Lan Barnes wrote:
> On Thu, March 22, 2007 2:08 pm, John Oliver wrote:
>> On Thu, Mar 22, 2007 at 01:51:35PM -0700, James G. Sack (jim) wrote:
>>> It appears that you  didn't grasp the significance of what Greg said
>>> about the '&&' separating your commands.
>>>
>>> If you want to:
>>>   try A, and then if that works try B, and then if that works try C
>>>   use
>>>     A &&
>>>     B &&
>>>     C
>>> if you want to:
>>>   try A, and then (always) try B, and then (always) try C
>>>   use
>>>     A
>>>     B
>>>     C
>> Ahhh!
>>
>> I thought the && would just move on to the next command after the
>> completion, not necessarily the successful completion, of the first
>> command.  And that's what I want... I want it to try to install libgcc
>> first, and only after that's complete, one way or the other, to move on
>> to the next RPM command.
>>
>> I need to look up bash characters :-)
>>
>>
> 
> OR (||) quits if the first is true, but checks the second if the first is
> false. AND (&&) quits if the first is false but checks #2 if the first is
> true.
> 
> Their clever use to do conditionals in command lines is further obscured
> by the fact that most posix programs return 0 for success (FALSE).

It's a cultural thing, I suppose. The association of FALSE with 0 is
what appears reasonable to you, I suspect. In this context it is more
consistent to say that 0 means NO-ERROR.

Anyway, the bash conditionals were designed to avoid having to think
about return codes. You don't (usually) need to examine return codes.

 If (operation)
 then
  <success branch>
 else
  <failure branch>
 fi

and

 operation && successaction || failureaction

Both seem _reasonable_ to me. ;-)


> 
> I have always been ambivalent about this bit of cleverness, because I
> distrust cleverness in programming in the first place, and because I fear
> that if I have to move my lips when I puzzle it out as I write it, then
> the next person to read it might just "correct" it into the third circle
> of hell. But it does work if you get it right.
> 

Regards,
..jim


-- 
KPLUG-List@kernel-panic.org
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-list

Reply via email to