title: Shell Script If Statement to compare dates
body: <p>I am currently working on a shell script to run some hive queries I have.  I need to check the last date in the table before I run it.  I want to check the date and pass it as a result then compare it to my date variable.  I am doing this as an if statement so if the date is yesterday then it should run the hive query.  If not(which means the date is older and the data hasn't been refreshed) I just want it to send me an email telling me so.  I have all of the logic figure out except how to compare the dates.  Every thing I try with reguards to = or -gt, -lt etc.  I always get the THEN statement, it will no check the first compare as matching.  Below is the code I used.  I have the then statement, even tell me what dates it finds.  So even the email will say the VAL1 = 2020-06-26 and yesterday was 2020-06-26( I set it to pick this date bc this is whta I am testing with.  So the output tells me that the dates are the same, but the IF statement is not marking them as true.</p>
  <p>This is my query:</p>
  <pre><code>#!/bin/bash
  yesterday=`date -d &quot;$date -3 days&quot; +&quot;%Y_%m_%d&quot;`;
  today=`date '+%Y_%m_%d'`;
  
  cd /idn/home/chalse/AutoJobs
  result=`hive -e &quot;set hive.cli.print.header=false;select max(asgn_dt) from acorn_data.katie_rr;&quot;`
  
  if [ $result -eq $yesterday ]
  then
  
  echo &quot;Hi Katie,
  
  The last update for Reserve &amp; Reactivation was $result .
  
  Yesterday is $yesterday
  
  Thanks, 
  CJ&quot; | mailx -s &quot;Reserve Reactivation Report $yesterday&quot; - name@email.com
  
  else 
  
  echo &quot;Hi KAtie,
  
  The last update for Commission File was $result.   We even checked $today but we did not check $yesterday
  
  Thanks,
  CJ&quot; | mailx -s &quot;Reserve Reactivation Report $today&quot; - name@email.com
  
  fi
  </code></pre>
  <p>I get this as my email showing the then statement The first date represents the output from the select hive query variable.  The second is just today varilable, and the third date is the $yesterday  Even though the outputs both show that the answer is 2020-06-26 the IF statement doesn't recognize them as matching.</p>
  <pre><code>&quot;Hi KAtie,
  
  The last update for Commission File was 2020-06-26($result).   We even checked 2020_06_29($today) but we did not check 2020-06-26($yesterday)
  
  Thanks,
  CJ&quot;
  </code></pre>