Page 1 of 1

Bash Script to Check Basename

PostPosted: Thu Jul 17, 2014 1:06 am
by brs
I have a folder of files that will be modified daily. I'm trying to have a passes script condition find the file with the basename that matches the current month and day. I will then take an action on that file.

File names are:
01-05.html
05-03.html
11-15.html
07-16.html
...

assuming today is July 16th (month 07), I should match the bottom file.

I've tried numerous iterations but cannot get a match to occur. Here's the latest iteration:

today=`date +%m`"-"`date +%d`
if [ "$(basename "$1")" == "$today" ]; then exit 0; else exit; fi

Any help is greatly appreciated, thank you.

Re: Bash Script to Check Basename

PostPosted: Thu Jul 17, 2014 11:26 am
by Mr_Noodle
This is more of a general shell scripting question than a Hazel one but if you break down your script, you'll see that running basename on the file keeps the extension intact so you'll need to either strip that off or add the extension to your "today" variable.

Re: Bash Script to Check Basename

PostPosted: Thu Jul 17, 2014 12:08 pm
by brs
Thanks, I'll give that a shot.