Full Flavour Behaviour!

No such file or directory in Unix shell script
October 19th @ 1:43pm

Okay, so many people won't know what the hell I'm on about here but this just wasted a hell of a lot of my time. It turns out that shell script paths don't work if you use crlf (Windows) line endings.

Here's an exmple. Let's say you have a script that runs fine from the browser and from the command line but for whatever reason (cron doesn't run from your htdocs directory for example) you want to set up a shell wrapper. So you write this:

cd $HOME/scripts
php myscript.php

But when you run it from the command line the response is:

: No such file or directory line 2: cd: /htdocs/scripts
Status: 404 Not Found
X-Powered-By: PHP/5.2.17
Content-type: text/html

No input file specified.

Well, turns out it could well be because you used CRLF instead of LF line endings. Merely changing to LF will make the script run perfectly.

I know, I know.

Comment on this entry

Don't miss..

Other Carl sites

Photo galleries