LINUX Multiple condition in IF Statement - Pls help

Hi All,

I am trying to put multiple conditions in an IF Statement (using $$). the Linux script somehow doesnt like it. The logic I am trying to implement is as follows,

  1. I will first search for DateFile.txt
  2. If it exists & there is a P_BUS_DATE value in it, then assign the date value to BUS_DATE else assign Current day value to it.

Pls find the part of the script i am trying the above logic,

---------------------------------------------------------------

file_exist=`ls $COMMON_TMP/DateFile.txt`
Dyn_file_chk=$?
if [[ $Dyn_file_chk == 0]] && [[`cat filedir/DateFile.txt | grep -q 'P_BUS_DATE' == 0`]];
then 
  export BUS_DATE=`cat filedir/DateFile.txt | grep 'P_BUS_DATE' | cut -d"=" -f2`
else 
  export BUS_DATE=`date "+%Y%m%d"`
fi

---------------------------------------------------------------
Can you pls tell me what I am doing wrong here.
Thanks for your help

Freddie

grep -iqw P_BUS_DATE $COMMON_TMP/DateFile.txt 2>/dev/null
if [ $? -eq 0 ];then
    BUS_DATE=`grep -i P_BUS_DATE | cut -d  = -f 2`
else
    BUS_DATE= `date "+%Y%m%d"`
fi

At any rate you need to leave space around the square brackets:

if [[ $Dyn_file_chk == 0 ]]
                        ^
                        |

Thank You Shailesh for your reply.

I am curious abt the below command grep -iqw.
Will it help me to check whether the Datefile is available as well as the particular string is present in it ? Can you Pls clarify. ( My requirement is to search for the DateFile as well as the existance of the string P_BUS_DT in it)

Thanks much
Freddie

well if the file doesn't exist return code of grep will non 0 and so it will if file exists but your pattern doesn't exist in file. Meaning the return code of grep -iqw P_BUS_DATE $COMMON_TMP/DateFile.txt 2>/dev/null will be 0 only if file exist and pattern is found in file.

I got it Shailesh. Looks like it is working:)

Do you know whether the 2>/dev/null directory will be the same in PROD as well ?

Thanks for your help
Freddie