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

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

Any ideas why it isn't working?

2 Answers 2


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.


The date utility bundled with OS X is not GNU date (which accepts the --date option).

You can use homebrew to install it.

You can probably use Perl to get what you want:

perl -MPOSIX=strftime -le 'print strftime("%d-%m-%Y",localtime(time()-86400))'
# or
perl -MTime::Piece -MTime::Seconds -le 'print((Time::Piece->new - ONE_DAY)->dmy)'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .