APM: #! /usr/bin/perl -wT MORE DETAILS

Tim McDaniel tmcd at panix.com
Thu Oct 19 11:47:06 PDT 2006


On Thu, 19 Oct 2006, CaptNemo <CaptNemo at Austin.rr.com> wrote:
>> I assume you are editing files on windows?
>
> I am using windows AND Vi on linux
...
> Broken version:
>
> user at www:~/public_html/cgi-bin$ head -n 1 dbquery.pl | od -cx
> 0000000   #   !       /   u   s   r   /   b   i   n   /   p   e   r   l
>         2123 2f20 7375 2f72 6962 2f6e 6570 6c72
> 0000020  \r  \n
>         0a0d
> 0000022
...
> ...bash returns:
> ": No such file or directory

It's the trailing carriage return that's the problem.  Linux is not
recognizing it as line-ending.

On the NetBSD system I'm on, messages are a little different:
     #! /usr/local/bin/perl^M
(^M represents the carriage return) results in
     -bash: local/test/005.pl: /usr/local/bin/perl^M: bad interpreter:
      No such file or directory
(which is actually bash passing on a kernel error status)

while
     #! /usr/local/bin/perl ^M
results in
     Can't open perl script "^M": No such file or directory
(which is perl reporting a file-no-found error).

The base problem is the same: \r (^M) is not seen by the kernel as a
whitespace character.

The reason that
     #! /usr/local/bin/perl -w ^M
works is because the kernel allows only one command-line argument on a
"#!" line -- so "-w" takes that place.

The main solution, IF you're not trying to keep scripts in synch on
Windows and Linux, is to strip trailing carriage returns on lines on
the Linux side.  If you can't do that, see below.

If you really want perl to have no arguments and have DOS-format file,
try
     #! /usr/local/bin/perl -- ^M
"--" ends the options on a Perl command line, so it's harmless;
space ends the "--"; the control-M then is shuffled off into
invisibility.  Apparently Perl then ignores the line-ending carriage
returns in the rest of the script.

-- 
Tim McDaniel, tmcd at panix.com


More information about the Austin mailing list