[DCPM] windows newlines in #! line

Dave Cross user_groups at pm.org
Thu Jul 20 12:24:04 PDT 2006


Steve Marvell wrote:
> This started as a CGI problem. Apparently, some of the Perl scripts a
> particular company provide are littered with Windows newlines. This
> casuse a bad interpretor error.
> 
> This is also the case if the script is run by hand.
> 
> I understand that the present version of a Apache the clinet is using
> handles this. 
> 
> I take this is a shell problem, but I think it could be solved if
> Apache prestripped them
> 
> Anyone got any ideas?

The problem is that your shebang line has a Windows newline character on 
the end. It therefore looks something like this:

   #!/usr/bin/perl\r\n

Unix recognises the \n as the end of the line and therefore looks for a 
program called

   /usr/bin/perl\r

And (usually) that doesn't exist.

Of course, you shouldn't be seeing this problem as your shebang line 
should look like this:

   #/usr/bin/perl -T\r\n

In this case, the shell correctly extracts the path to Perl and passes 
the slight broken command line argument (-T\r) to Perl. Perl can deal 
with broken line endings just fine, so this will fix the problem.

Of course, you'll then find that your program isn't taint-clean and 
that'll give you some far more serious problems to fix :)

Dave...



More information about the Devoncornwall-pm mailing list