mardi 21 juillet 2020

IF condition not working to compare variables in bash

i am trying to execute a IF condition inside a while loop, But the IF condition comparison operator isn't working as expected! kindly guide me through the proper way to compare two variables in IF condition.

Note - It was supposed to go to 'hello' not 'hi'

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
        echo 'hello'
        "$file" > path/tempc
     else
        echo 'hi'
 
     fi
done

Error log -

phase2
2020-07-21 05:22:28.000000000 -0400
2020-07-21
2020-07-21
hi

Aucun commentaire:

Enregistrer un commentaire