Discussion: using if
Afficher un message
Vieux 11/09/2007, 11h41   #3
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: using if

2007-09-11, 00:38(-07), moonhk:
> Hi all
>
>
> What is different between
>
> if [ "${rtn}" = "0" and "${rtn2}" = "2" ] && [ ${rtn3} = 3 ] ; then
>
> if [ "${rtn}" = "0" ] && [ "${rtn2}" = "2" ] && [ ${rtn3} = 3 ] ;
> then

[...]

I don't know of any shell or "[" implementation that accepts
"and" as a "[" operator.

In any case, "[" is unreliable when passed more than 3 operands,
so the second form should be prefered. Though, I'd probably
write it:

[ "$rtn" -eq 0 ] && [ "$rtn2" -eq 2 ] && [ "$rtn3" -eq 3 ]

And note that it's not the "if" syntax, but the "[" command
syntax here we're discussing here. What's between "if" and
"then" is just a list of commands.

--
Stéphane
  Réponse avec citation
 
Page generated in 0,04714 seconds with 9 queries