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
|