bash shell script for yesterdays date (last working day)

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.

I found that this prints yesterdays date:

date -d '1 day ago' +'%Y/%m/%d'

I also know that I can get the day of the week by using this statement

date +%w

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)

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'`

Can someone help by correcting the pseudo code above?

(I am running on Ubuntu 10.0.4)

11
задан MrTux 13 February 2019 в 07:44
поделиться