[Tutor] Is there space a between "#!" and "/usr/bin/env python" ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Tutor] Is there space a between "#!" and "/usr/bin/env python" ?

Santosh Kumar-2
Is there space a between "#!" and "/usr/bin/env python"?

I have seen Python manual, it says <#! /usr/bin/env python>
But snippet manager of many text editing programs have <#!/usr/bin/env
python>. Python is a strongly typed language, which one is correct?
_______________________________________________
Tutor maillist  -  [hidden email]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Tutor] Is there space a between "#!" and "/usr/bin/env python" ?

Dave Angel-3
On 05/01/2012 09:55 AM, Santosh Kumar wrote:
> Is there space a between "#!" and "/usr/bin/env python"?
>
> I have seen Python manual, it says <#! /usr/bin/env python>
> But snippet manager of many text editing programs have <#!/usr/bin/env
> python>. Python is a strongly typed language, which one is correct?
>

That's a comment, so it's irrelevant to Python.

That line is called a shebang line, and is used by the various Unix
command shells to specify what program shall interpret this particular
script.

I have no idea whether your shell will ignore a leading space or not.

The bash that happens to be on my system will ignore the leading space.



--

DaveA

_______________________________________________
Tutor maillist  -  [hidden email]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Tutor] Is there space a between "#!" and "/usr/bin/env python" ?

Flynn, Steve (L & P - IT)
In reply to this post by Santosh Kumar-2

> I have seen Python manual, it says <#! /usr/bin/env python>
> But snippet manager of many text editing programs have <#!/usr/bin/env
> python>. Python is a strongly typed language, which one is correct?

That's not python code - it's interpreted by the shell (on Linux/Unix)
to determine what to invoke to process the file - in this case the
python interpreter.

Whether there's a space there or not doesn't usually matter to the
shell, and python doesn't care because it's seen as a comment when the
code is compiled.

In short - either is fine.


This email and any attachment to it are confidential.  Unless you are the intended recipient, you may not use, copy or disclose either the message or any information contained in the message. If you are not the intended recipient, you should delete this email and notify the sender immediately.

Any views or opinions expressed in this email are those of the sender only, unless otherwise stated.  All copyright in any Capita material in this email is reserved.

All emails, incoming and outgoing, may be recorded by Capita and monitored for legitimate business purposes.

Capita exclude all liability for any loss or damage arising or resulting from the receipt, use or transmission of this email to the fullest extent permitted by law.
_______________________________________________
Tutor maillist  -  [hidden email]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Tutor] Is there space a between "#!" and "/usr/bin/env python" ?

Lie Ryan
In reply to this post by Santosh Kumar-2

> and is used by the various Unix command shells to specify what program
> shall interpret this particular script.

To be precise, the shell does not care about the shebang line either, the shebang is interpreted by the program loader in the kernel. The shell simply execve()-ed a script containing a shebang line just like a binary executable.


_______________________________________________
Tutor maillist  -  [hidden email]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Tutor] Is there space a between "#!" and "/usr/bin/env python" ?

Santosh Kumar-2
Its getting complicated now. Will it effect or not?
Give me one word answer with one line description.
_______________________________________________
Tutor maillist  -  [hidden email]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Tutor] Is there space a between "#!" and "/usr/bin/env python" ?

Leam Hall
On 05/01/2012 08:02 PM, Santosh Kumar wrote:
> Its getting complicated now. Will it effect or not?
> Give me one word answer with one line description.

"Experiment"  -- Try it and see...
_______________________________________________
Tutor maillist  -  [hidden email]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Tutor] Is there space a between "#!" and "/usr/bin/env python" ?

Alan Gauld
In reply to this post by Santosh Kumar-2
On 02/05/12 01:02, Santosh Kumar wrote:
> Its getting complicated now. Will it effect or not?
> Give me one word answer with one line description.

impossible.

It depends what OS you are on, but you didn't say.

If its Windows the line makes no difference.
If it's Unix it depends on the variety, but usually no space is needed.

Search shebang on wikipedia.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

_______________________________________________
Tutor maillist  -  [hidden email]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Tutor] Is there space a between "#!" and "/usr/bin/env python" ?

Steven D'Aprano-8
In reply to this post by Santosh Kumar-2
Santosh Kumar wrote:
> Its getting complicated now. Will it effect or not?
> Give me one word answer with one line description.

No. Either of these are fine:

#! /usr/bin/env python
#!/usr/bin/env python

This is not a Python trick. It will work for Ruby, or Perl, or any other
language with an interpreter.



--
Steven

_______________________________________________
Tutor maillist  -  [hidden email]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Tutor] Is there space a between "#!" and "/usr/bin/env python" ?

Steven D'Aprano-8
In reply to this post by Alan Gauld
Alan Gauld wrote:
> On 02/05/12 01:02, Santosh Kumar wrote:
>> Its getting complicated now. Will it effect or not?
>> Give me one word answer with one line description.
>
> impossible.
>
> It depends what OS you are on, but you didn't say.
>
> If its Windows the line makes no difference.

On Windows, the presence or absence of a space will make no difference,
because it's just a comment.


> If it's Unix it depends on the variety, but usually no space is needed.

As far as I know, on any Unix, Linux or other POSIX system, the presence or
absence of a space between the #! and the path is irrelevant. I suppose it is
possible that ancient Unixes from 1970 or something might not like the space,
but that would surprise me.



--
Steven

_______________________________________________
Tutor maillist  -  [hidden email]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Tutor] Is there space a between "#!" and "/usr/bin/env python" ?

Alan Gauld
On 02/05/12 01:27, Steven D'Aprano wrote:

>> If it's Unix it depends on the variety, but usually no space is needed.
>
> As far as I know, on any Unix, Linux or other POSIX system, the presence
> or absence of a space between the #! and the path is irrelevant.

So far as I know you are right. One thing nobody has mentioned is that
the presence of a space between the # and ! will usually (always?) not
work. I have been caught out by that before...

ie

#! /bin/sh
#!/bin/sh

will both work

# ! /bin/sh
# !/bin/sh
will not.


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

_______________________________________________
Tutor maillist  -  [hidden email]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
Loading...