[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: YABQ (Yet Another Bash Question)



> Why does:
> 
> if [ $A = $B ] || [ $A = $C ] && [ $D = fred ]

This runs test, comparing $A and $B, and if they are NOT equal, runs 
test again, comparing $A and $C.  If $A != $B AND $A = $C, then the 
shell runs test, comparing $D with "fred".  The result of all these 
testing is 1 if $A=$b or if $A=$C and $D="fred".  If that is the case, 
then if runs the then list of commands.

> 
> work fine, but:
> 
> if [ {$A = $B} -o {$A = $C} ] && [ $D = fred ]

This runs test, comparing {$A with both $B} and $C}.  If {$A equals 
either of these, then that test returns 1, and we then run test, 
comparing $D with fred.  If both of these conditions are true (that {$A 
equals eitherof $B} or $C} and that $D = fred), then we execute the 
then list of the overall if command.

Note I said compares {$A and $B}.  If $A = foo, and $B = foo, then the 
test is between the strings "{foo" and "foo}", which is probably not 
what you want.

> 
> doesn't work at all? (and produces no errors)
> 
> TIA,
> 
> Dwarf
> 
> ------------                                          --------------
> 
> aka   Dale Scheetz                   Phone:   1 (904) 877-0257
>       Flexible Software              Fax:     NONE 
>       Black Creek Critters           e-mail:  dwarf@polaris.net
> 
> ------------ If you don't see what you want, just ask --------------

-- 
     Buddha Buck                      bmbuck@acsu.buffalo.edu
"She was infatuated with their male prostitutes, whose members were
like those of donkeys and whose seed came in floods like that of
stallions."  -- Ezekiel 23:20



Reply to: