homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
Forum Library, Charter, Moderators: bakedjake

Linux, Unix, and *nix like Operating Systems Forum

Automating tidy with shell script
-bash: ./TidySite.sh: cannot execute binary file?

 9:05 pm on Oct 18, 2004 (gmt 0)

Newbie warning: I've never done any shell scripting! I have spent the last two hours doing my homework on this and I thought this was good code. Please be patient and if I'm all screwed up please let me know.

I have installed tidy [tidy.sourceforge.net] and would like to automate the task of tidying up all the .html files in a particular directory. However, I am getting this error message and am not sure why:

-bash: ./TidySite.sh: cannot execute binary file

Here's my shell script (saved as TidySite.sh, chmod to 0755):

# run tidy on all html files in particular directory
for FILE in `find /Volumes/Local\ Sites/sites/siteDynamic/ -name "*html"`;
tidy -config config.txt -asxhtml FILE

The line starting with 'tidy' runs correctly when fed the path to an individual file from the site.



 10:05 pm on Oct 18, 2004 (gmt 0)

I think you need $FILE in the tidy line

or you can use xargs:

find /Volumes/Local\ Sites/sites/siteDynamic/ -name "*html" -print0 ¦ xargs -0 tidy ...

The -print0 -0 options allow find/xargs to work with spaces in the filenames.


 11:45 pm on Oct 18, 2004 (gmt 0)

Using xargs gets it working when I run it from the command line. I'm really impressed, a single line of code and 400+ pages are all tidied up. Thanks for that suggestion, drbrain! :D

If I save it as a shell script, I still get the "cannot execute binary file" error. Revised code, same error:

find /Volumes/Local\ Sites/sites/siteDynamic -name "*html" -print0 xargs -0 tidy -config config.txt -asxhtml

Any suggestions?


 6:37 pm on Oct 19, 2004 (gmt 0)

But the exact same line works fine from the command line?

Is tidy in your PATH?

You should be able to add "echo $PATH" above the find ¦ xargs line to see what the command thinks your PATH is. If tidy is not installed in any of those directories, you need to either add the full path name to tidy to the script, or add the path to tidy to your PATH environment variable.


 10:30 pm on Oct 19, 2004 (gmt 0)

Thanks for your help drbrain! I had almost given up.

It's working now, I just realized the error message was that it thought the TidySite.sh file wasn't a text file.

I opened it in another text editor and resaved it and it worked beatifully after that. What's the correct encoding for a shell script? Shouldn't UTF-8 be correct?


 10:49 pm on Oct 19, 2004 (gmt 0)

Your script technically was not even supposed to touch files other than the ones that end with html. And your script ends with .sh. Something is wrong.


 4:17 pm on Oct 21, 2004 (gmt 0)


I had saved it UTF-8 with BOM. :(


Global Options:
 top home search open messages active posts  

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved