title: bash shell script for yesterdays date (last working day)
body: <p>I am writing a bash script that needs to print the date of the last working day. So for example if the script is run on a Monday, it will print the date for last Friday.</p>
  
  <p>I found that this prints yesterdays date:</p>
  
  <pre><code>date -d '1 day ago' +'%Y/%m/%d'
  </code></pre>
  
  <p>I also know that I can get the day of the week by using this statement</p>
  
  <pre><code>date +%w
  </code></pre>
  
  <p>I want to combine these two statements in order to have a little helper script that prints the required date. The logic goes something like this (note: its Pseudo code - I've never written a bash script)</p>
  
  <pre><code>DAY_OF_WEEK = `date +%w`
  if (%DAY_OF_WEEK == 1)
     LOOK_BACK = 3
  elif   
     LOOK_BACK = 1
  fi
  
  echo `date -d '%LOOK_BACK day ago' +'%Y/%m/%d'`
  </code></pre>
  
  <p>Can someone help by correcting the pseudo code above?</p>
  
  <p>(I am running on Ubuntu 10.0.4)</p>