Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 18 down vote accepted

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.

share|improve this answer

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)'
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.