Operating System - HP-UX
1832506 Members
4730 Online
110043 Solutions
New Discussion

Re: ksh nesting or conditions

 
SOLVED
Go to solution
Mike_Ca Li
Regular Advisor

ksh nesting or conditions

if [ -f /disk1/temp/o-abort -o -f /disk2/temp/a-abort -o -f /disk3/temp/b-abort -o -f /disk4/temp/q-abort -o -f /disk5/temp/m-abort -o -f /disk6/temp/e-abort ]; then
do stuff
fi

or
if ! [ -f /disk1/temp/o-abort -o -f /disk2/temp/a-abort -o -f /disk3/temp/b-abort -o -f /disk4/temp/q-abort -o -f /disk5/temp/m-abort -o -f /disk6/temp/e-abort ]; then
do stuff
fi

How to achieve the above in ksh?
Thanks.
3 REPLIES 3
Sridhar Bhaskarla
Honored Contributor
Solution

Re: ksh nesting or conditions

Hi,

#!/usr/bin/ksh

if [[ -f /disk1/temp/o-abort || -f /disk2/temp/a-abort || -f /disk3/temp/o-abort ]]
then
do_suff
fi

Same case with !.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
curt larson_1
Honored Contributor

Re: ksh nesting or conditions

well not quite

! [[ ... ]] is only on version of ksh newer then 11/16/88, which HP's /usr/bin/ksh isn't

so you cannot do

if ! [[ -f /disk1/temp/o-abort || -f /disk2/temp/a-abort ]]
then
do_suff
fi

you'll have to use the else portion of the if statement
if [[ -f /disk1/temp/o-abort || -f /disk2/temp/a-abort ]]
then
not do
else
do_suff
fi

or negate the test operands

if[[ ! -f /disk1/temp/o-abort && ! -f /disk2/temp/a-abort ]]
then
do_suff
fi
Rodney Hills
Honored Contributor

Re: ksh nesting or conditions

According to the man page for ksh, "!" is available in the form [[ ! expression ]].

Using "(" and ")" you could get the result by-

if [[ !(-f /disk1/temp/o-abort || -f /disk2/temp/a-abort || -f /disk3/temp/b-abort || -f /disk4/temp/q-abort || -f /disk5/temp/m-abort || -f /disk6/temp/e-abort) ]]; then
do stuff
fi

HTH

-- Rod Hills
There be dragons...