Bash Script to Check Basename

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Bash Script to Check Basename 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.
brs
 
Posts: 2
Joined: Thu Jul 17, 2014 1:01 am

Re: Bash Script to Check Basename 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.
Mr_Noodle
Site Admin
 
Posts: 11866
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Bash Script to Check Basename Thu Jul 17, 2014 12:08 pm • by brs
Thanks, I'll give that a shot.
brs
 
Posts: 2
Joined: Thu Jul 17, 2014 1:01 am


Return to Support

cron