Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Shebang line on Windows?

Reply
Thread Tools

Shebang line on Windows?

 
 
D'Arcy J.M. Cain
Guest
Posts: n/a
 
      02-25-2013
On Mon, 25 Feb 2013 10:18:44 -0700
Michael Torrie <(E-Mail Removed)> wrote:
> On 02/25/2013 06:14 AM, Dave Angel wrote:
> > It's not Python that needs dos2unix, it's bash or equivalent. For
> > some reason, bash shebang processing still isn't tolerant of a
> > trailing cr on the line. Python doesn't care.

>
> Actually, the shell isn't involved in parsing the shebang line at all.
> That's actually done in the kernel by the program loader. So it's the
> kernel that has a problem with it; wonder if Linus would accept a
> patch to ignore the tailing CR?


So much the wrong solution. First of all, I don't think that Linus is
on the bash development team so he can't help there. Also, bash is not
the only shell in the world. And, Linux is not the only operating
system in the world. There are still a lot of Unix systems (the system
that Linux is a clone of) out there. FreeBSD, NetBSD, Solaris, Mac
OSX, etc. You can't expect all of them to bend over backwards for
every Windows wart out there.

I don't run Windows myself so I can't test it but doesn't Python on
Windows work fine with Unix style EOL? So why not strip out the CR and
run the same file everywhere?

--
D'Arcy J.M. Cain <(E-Mail Removed)> | Democracy is three wolves
http://www.druid.net/darcy/ | and a sheep voting on
+1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.
IM: http://www.velocityreviews.com/forums/(E-Mail Removed), VOIP: sip:(E-Mail Removed)
 
Reply With Quote
 
 
 
 
David Robinow
Guest
Posts: n/a
 
      02-25-2013
On Mon, Feb 25, 2013 at 12:29 PM, D'Arcy J.M. Cain <(E-Mail Removed)> wrote:
> ...
> I don't run Windows myself so I can't test it but doesn't Python on
> Windows work fine with Unix style EOL? So why not strip out the CR and
> run the same file everywhere?

That's the ideal solution, but so many Windows tools default to text
mode that it's easy to create the wrong type file, especially for
beginners who are moving there code to Linux for the first time. I've
done it myself, even though I should no better by now.
In addition, the error message is rather obscure (if I remember right
- I'm not near my Ubuntu at the moment and Cygwin handles this fine,
as it should)
I'm afraid this problem won't go away. People are just going to have
to learn from experience.
 
Reply With Quote
 
 
 
 
Michael Torrie
Guest
Posts: n/a
 
      02-25-2013
On 02/25/2013 10:29 AM, D'Arcy J.M. Cain wrote:
> So much the wrong solution. First of all, I don't think that Linus is
> on the bash development team so he can't help there. Also, bash is not
> the only shell in the world.


Ooops you didn't read what I said. The shebang parsing is not done by
bash. It's done by the kernel. So it has nothing to do with bash or
any shell for that matter.

> And, Linux is not the only operating
> system in the world. There are still a lot of Unix systems (the system
> that Linux is a clone of) out there. FreeBSD, NetBSD, Solaris, Mac
> OSX, etc. You can't expect all of them to bend over backwards for
> every Windows wart out there.


Yup. This is true. My suggestion was tongue in cheek.
 
Reply With Quote
 
Michael Torrie
Guest
Posts: n/a
 
      02-25-2013
On 02/25/2013 10:29 AM, D'Arcy J.M. Cain wrote:
> I don't run Windows myself so I can't test it but doesn't Python on
> Windows work fine with Unix style EOL? So why not strip out the CR and
> run the same file everywhere?


As has been said on this thread, python is perfectly happy on windows
with the Unix-style EOL. And if you use a good programmer's editor, it
will happily keep unix-style line endings. Use a crappier,
windows-centric editor, and you'll see the CR's creeping back in.

 
Reply With Quote
 
Steven D'Aprano
Guest
Posts: n/a
 
      02-26-2013
On Mon, 25 Feb 2013 12:29:58 -0500, D'Arcy J.M. Cain wrote:

> On Mon, 25 Feb 2013 10:18:44 -0700
> Michael Torrie <(E-Mail Removed)> wrote:
>> On 02/25/2013 06:14 AM, Dave Angel wrote:
>> > It's not Python that needs dos2unix, it's bash or equivalent. For
>> > some reason, bash shebang processing still isn't tolerant of a
>> > trailing cr on the line. Python doesn't care.

>>
>> Actually, the shell isn't involved in parsing the shebang line at all.
>> That's actually done in the kernel by the program loader. So it's the
>> kernel that has a problem with it; wonder if Linus would accept a patch
>> to ignore the tailing CR?

>
> So much the wrong solution. First of all, I don't think that Linus is
> on the bash development team so he can't help there.


/facepalm

Perhaps you forgot to read Michael's comment before criticising it?

The bash dev team is irrelevant, because this is not a bash problem. It
is the kernel, not bash, that reads the shebang line. So yes, Linus
Torvalds could fix this problem if he chose.


> Also, bash is not
> the only shell in the world. And, Linux is not the only operating
> system in the world. There are still a lot of Unix systems (the system
> that Linux is a clone of) out there. FreeBSD, NetBSD, Solaris, Mac OSX,
> etc. You can't expect all of them to bend over backwards for every
> Windows wart out there.


Nobody is asking anyone to support "every Windows wart out there".
Windows-style line separators are not a wart, it is a convention used by
many, many tools, operating systems, data formats (e.g. email), etc. It
is an old, old convention, going back to teletype days and so predating
not just Windows but also Unix. So in fact it is *Unix* that broke the
convention, and Unix line separators which is the "wart" (or at least a
regression).


--
Steven
 
Reply With Quote
 
Michael Torrie
Guest
Posts: n/a
 
      02-26-2013
On 02/25/2013 05:52 PM, Steven D'Aprano wrote:
> Nobody is asking anyone to support "every Windows wart out there".
> Windows-style line separators are not a wart, it is a convention used by
> many, many tools, operating systems, data formats (e.g. email), etc. It
> is an old, old convention, going back to teletype days and so predating
> not just Windows but also Unix. So in fact it is *Unix* that broke the
> convention, and Unix line separators which is the "wart" (or at least a
> regression).


That's really interesting. I didn't know that before. It does make
sense. As much as I love unix, it really originated as a hack in many
senses. With that in mind I think Linux should allow a trailing CR in
the shebang line, even if other unix OS's don't. Of course it's a minor
thing, and there are ways of dealing with it.

This is a reminder to me how much we Linux users look at Windows as a
quaint anomaly with it's apparently backwards ways of doing things (like
backslash directory separators, like CP/M did), but forget it is still
the dominant platform out there for general purpose computing. So it
really could be argued that Linux indeed is the backward OS when it
comes to these kind of incompatibilities (though I still think I like it
better!)

 
Reply With Quote
 
Dave Angel
Guest
Posts: n/a
 
      02-26-2013
On 02/25/2013 09:08 PM, Michael Torrie wrote:
> <snip>
> This is a reminder to me how much we Linux users look at Windows as a
> quaint anomaly with it's apparently backwards ways of doing things (like
> backslash directory separators, like CP/M did),


Actually the reason MSDOS used backslash was because it had already used
the forward slash for a switch-character. Then for version 2, with hard
disks being supported for the first time, they used the backslash
instead. At the time I talked them into supporting a "switchchar" call
to change to using the dash for switch character, and slash for
subdirectories.

But the idea was never publicized, so it never caught on. And future
versions of utilities generally paid no attention to the value of
switchchar.

By the time Windows split off from MSDOS (NT 3.1), the support in the OS
for both slash and backslash was well established. But the utilities
never grew up.

Yes, using the slash as a switch-character was inherited from CP/M,
through QDOS, then MSDOS.


On some of the old teletypes, if the data was coming in fast enough, you
could see the first character of the next line printed before the typing
element reached the left margin. So newline was then spelled CR/LF/NULL
or even CR/LF/NULL/NULL

Buffering? What's that?

--
DaveA
 
Reply With Quote
 
MRAB
Guest
Posts: n/a
 
      02-26-2013
On 2013-02-26 02:08, Michael Torrie wrote:
> On 02/25/2013 05:52 PM, Steven D'Aprano wrote:
>> Nobody is asking anyone to support "every Windows wart out there".
>> Windows-style line separators are not a wart, it is a convention used by
>> many, many tools, operating systems, data formats (e.g. email), etc. It
>> is an old, old convention, going back to teletype days and so predating
>> not just Windows but also Unix. So in fact it is *Unix* that broke the
>> convention, and Unix line separators which is the "wart" (or at least a
>> regression).

>
> That's really interesting. I didn't know that before. It does make
> sense. As much as I love unix, it really originated as a hack in many
> senses. With that in mind I think Linux should allow a trailing CR in
> the shebang line, even if other unix OS's don't. Of course it's a minor
> thing, and there are ways of dealing with it.
>
> This is a reminder to me how much we Linux users look at Windows as a
> quaint anomaly with it's apparently backwards ways of doing things (like
> backslash directory separators, like CP/M did), but forget it is still
> the dominant platform out there for general purpose computing. So it
> really could be argued that Linux indeed is the backward OS when it
> comes to these kind of incompatibilities (though I still think I like it
> better!)
>

That reminds me of the time I was making PPD (PostScript Printer
Description) files. They worked on both Windows and MacOS.

Then Apple released MacOS X, which complained when they were installed.

It turned out that MacOS X didn't like the line endings. It insisted on
CR only, despite the fact that the PPD specification said that the line
endings could be CR, LF, or CR/LF, and that they had followed the
specification previously!

 
Reply With Quote
 
Dennis Lee Bieber
Guest
Posts: n/a
 
      02-26-2013
On Mon, 25 Feb 2013 19:08:08 -0700, Michael Torrie <(E-Mail Removed)>
declaimed the following in gmane.comp.python.general:


> That's really interesting. I didn't know that before. It does make
> sense. As much as I love unix, it really originated as a hack in many
> senses. With that in mind I think Linux should allow a trailing CR in
> the shebang line, even if other unix OS's don't. Of course it's a minor
> thing, and there are ways of dealing with it.
>

Even the <cr><lf> ORDER goes back to teletypes. It took more time
for the <cr> to complete than the <lf> so putting it first allowed the
print head to continue moving left when the <lf> rotated the platen
upward (and on a particularly slow system, with paper tape, one could
use <cr><lf><rubout> to give more time).
--
Wulfraed Dennis Lee Bieber AF6VN
(E-Mail Removed) HTTP://wlfraed.home.netcom.com/

 
Reply With Quote
 
Anssi Saari
Guest
Posts: n/a
 
      02-26-2013
Michael Torrie <(E-Mail Removed)> writes:

> Actually, the shell isn't involved in parsing the shebang line at all.
> That's actually done in the kernel by the program loader. So it's the
> kernel that has a problem with it; wonder if Linus would accept a patch
> to ignore the tailing CR?


Worth a try in my opinion. There's some historical information about the
shebang at http://www.in-ulm.de/~mascheck/various/shebang/ There's a
table which says Linux since 2.4.0 removes trailing whitespace from the
shebang line. I guess Linux doesn't count CR as whitespace in this
context.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Where can I find the 'shebang' line? Ast Jay Ruby 5 07-27-2010 09:20 PM
Shebang line problems and python Blaine Python 11 09-17-2009 09:24 PM
Is "#!/usr/bin/env python" the better shebang line ? Timothy Madden Python 4 09-07-2009 08:05 AM
Shebang! line not recognized in OS X Leopard?? Johnnie Lieske Ruby 6 11-28-2008 02:25 PM
Optimize flag on shebang line Andres Corrada-Emmanuel Python 0 12-09-2003 07:02 PM



Advertisments