Discussion: using if
Afficher un message
Vieux 12/09/2007, 04h59   #4
moonhk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: using if

On 9 11 , 5 41 , Stephane CHAZELAS <this.addr...@is.invalid> wrote:
> 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


Thank
I will check using [] && [] & [] when more than 2 operands.

  Réponse avec citation
 
Page generated in 0,05241 seconds with 9 queries