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

2007-09-11, 19:59(-07), moonhk:
> 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

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

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


What I meant is that for instance

[ "${rtn}" = "0" -a "${rtn2}" = "2" ]

That is where the "[" command is passed in this case 7 arguments
(beside the [ and ] ones)

is unreliable.

For instance if $rtn is "!", many "[" implementations will
output an error.

[ "${rtn}" = "0" ] && [ "${rtn2}" = "2" ]

is OK with POSIX shells whatever the value of $rtn or $rtn2.

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