Shell Script for Yesterday’s Date

command lineterminal

I'm trying to execute the following shellscript with hazel app on any file in the folder. It works, but the only thing thats causing a problem is the date for yesterday.

#! /bin/bash

saveDir="TJ"
dd=$(date --date='yesterday' +'%m-%d-%Y')
for file in *.csv ; do
    saveName="${saveDir}/TJ ${dd}.csv"
    cut -d',' -f2,14 "$file" > "$saveName"
done

Any ideas why it isn't working?

Best Answer

Try using date like this:

dd=$(date -v -1d '+%m-%d-%y')

as mentioned yesterday is part of GNU Date, but using an offset of -1d should be equivalent for OS X use.