Operating System - HP-UX
1848954 Members
6780 Online
104039 Solutions
New Discussion

Re: if test condition question

 
SOLVED
Go to solution
Hunki
Super Advisor

if test condition question

if [ $a -lt 7 -a [ $b -eq 16 -o $b -eq 8 ] ]

I want the following condition :

$a less than 7 and also $b should be either equal to 16 or it should be equal to 8. The above that I have gives me the following error :

[13]: 13: unknown test operator
3 REPLIES 3
James R. Ferguson
Acclaimed Contributor
Solution

Re: if test condition question

Hi Hunki:

The syntax is:

if [ $a -lt 7 -a \( $b -eq 16 -o $b -eq 8 \) ]

...note the escaped parentheses.

Regards!

...JRF...
Ivan Ferreira
Honored Contributor

Re: if test condition question

Try this:

if [ $a -lt 7 ] && ( [ $b -eq 16 ] || [ $b -eq 8 ] ); then
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Hunki
Super Advisor

Re: if test condition question

Thanks !