ksh - if examples
## ksh - if statements examples

## Operators:
 and is && 
 or is ||
 not is !

## Multiple imbedded if-then-else
if [[ ${NEW_VALUE} = TRUE ]]
then OLD_VALUE=FALSE
else
   if [[ ${NEW_VALUE} = FALSE ]]
   then OLD_VALUE=TRUE
   else echo "Invalid Value: must be TRUE or FALSE"
      exit 1
   fi
fi

## check return code from previous step
if [ $? = 0 ]
then echo "Return is 0" 
else echo "`date` ERROR - copy restore script" >> $HBK_ERROR_LOG
     echo "ERROR copy restore script Step "
fi

## if with numeric test
if (( `grep -c $FIND_WHAT $FILE` > 0 ))
then
   echo $FILE contains
fi                                                          

## if with numeric test
if (( ${nbr_of_dirs} == 0 )); then
   echo 1
else
   if (( ${nbr_of_dirs} > 1 )); then
	   echo 2
   else
	   echo 3
   fi
fi

## check if a string is equal to another string
if [[ `echo $LINE | awk -F: '{print $1}'` = $1 ]]
then
   ORACLE_SID=$1
fi                                

## check if 2 values are not equal
if [ ! ${Bgn_Bkp} -eq `expr ${End_Bkp} + ${Diff_Bkp}` ]; then
   echo "`date` ERROR - Number of alter backup does not balance, investigate immediately" >> $HBK_ERROR_LOG
else
   echo " " >> ${HBK_LOG} 
   echo "Hot backup for $ORACLE_SID has successfully completed" >> ${HBK_LOG} 
fi

## check if a file exists
if [ -f $ORACLE_HOME/dbs/sgadef${ORACLE_SID}.dbf ] 
then echo "file exists"
else echo "file does not exist"
fi

## check if a file is non-zero size
if [ -s $ORACLE_HOME/dbs/sgadef${ORACLE_SID}.dbf ] 
then echo "file size > 0"
else echo "file size = 0"
fi