Embedded Script Not Working

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

Moderator: Mr_Noodle

Embedded Script Not Working Mon Mar 26, 2012 12:17 am • by IDontDoWindows
Code: Select all
shell is /bin/bash

textFileName=basename "$1"
/usr/local/bin/mtcmail -t me@me.com -b me@me.com -s "$textFileName - la de dah"


Not working. Sends the email, but does not include the file name. I've attempted various versions of this, and none of them work.
IDontDoWindows
 
Posts: 57
Joined: Sun Jan 07, 2007 5:43 am

Re: Embedded Script Not Working Mon Mar 26, 2012 2:06 pm • by Mr_Noodle
In general, it's a good idea to test scripts outside of Hazel first.

In this case, the first line is incorrect. You are just setting the variable textFileName to the string basename...

If you want basename to be executed and the output applied to the variable, you need to do:

Code: Select all
textFileName=`basename "$1"`


Note that those are backticks, not single quotes. If you are typing on a US keyboard, it's the key in the upper left.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Embedded Script Not Working Mon Mar 26, 2012 5:42 pm • by sjk
Mr_Noodle wrote:Note that those are backticks, not single quotes.

Alternatively, use $(…) instead of backticks for command substitution, i.e.:

Code: Select all
textFileName=$(basename "$1")
sjk
 
Posts: 332
Joined: Thu Aug 02, 2007 5:43 pm
Location: Eugene

Re: Embedded Script Not Working Tue Mar 27, 2012 2:36 pm • by IDontDoWindows
Thanks. That was driving me nuts.

Now if I could remember what I was working on when I was trying to do that...
IDontDoWindows
 
Posts: 57
Joined: Sun Jan 07, 2007 5:43 am


Return to Support