1833059 Members
2526 Online
110049 Solutions
New Discussion

using korn shell

 
SOLVED
Go to solution
intp
Frequent Advisor

using korn shell

using korn shell how to code the following without nested if statements.

if ((a=1 OR b=3) AND (c=4))
3 REPLIES 3
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: using korn shell


typeset -i A=1
typeset -i B=6
typeset -i C=4

if [[ ( ${A} = 1 || ${B} = 3 ) && ${C} = 4 ]]
then
echo "True"
else
echo "False"
fi


The syntax is different if you use the more traditional '[ ]' (single bracket) syntax because that invokes the external test command rather than ksh's internal evaluation.
If it ain't broke, I can fix that.
Jeff_Traigle
Honored Contributor

Re: using korn shell

I would do it like this. It works for any of the Bourne-like shells.

if [ \( $a -eq 1 -o $b -eq 3 \) -a $c -eq 4 ]
--
Jeff Traigle
intp
Frequent Advisor

Re: using korn shell

thanks all.