0

i am trying to execute a IF condition inside a while loop, But the IF condition isn't working as variables aren't expanding! kindly guide me through the proper way to compare two variables in IF condition Note - if you can see the error log - DATE was expanding thou! problem with mdate

DATE=`date +"%Y-%m-%d"`
cat path/temp_b | while read file

 
do
    
    echo 'phase2'
    mtime=$(stat -c '%y' $Src_Dir/$file)
    echo $mtime
    mdate= echo $mtime | cut -d ' ' -f1
    echo $mdate
    echo $DATE
     if ["$mdate"=="$DATE"]; then
        "$file" > path/tempc
     else
        echo 'hi'
 
     fi
done

**Error log -

phase2

2020-05-07 05:22:28.000000000 -0400

2020-05-07

2020-07-21

./test1.ksh: line 37: [==2020-07-21]: command not found

hi**

Alekhya varma
  • 93
  • 2
  • 8

1 Answers1

0

Change your if statement like:

if [ "$mdate" == "$DATE" ]; then

Explanation: if in bash needs to have square brackets, operator, and operand to be space-separated.

Avinash Yadav
  • 781
  • 7
  • 13