Must the shebang header always match the interpreter's installation directory? If so, then why do both #!/usr/bin/python and #!/usr/local/bin/python work for me?
|
|
||||
|
As others have noted, the shebang line must refer to an actual file that exists. Since different systems can have binaries installed to different locations, this is a weakness of script portability. One way to solve this is with links, as others have mentioned. Another way is to edit the script to refer to the right path on your system. One more way to get around this is to use So instead of:
Write:
This way, people just have to symlink Of course, the executable still has to be in your PATH for this to work... As you can see, there is no 100% clean solution. Remember: "Worse is Better" (: |
|||
|
|
|
The Normally, you'd get an error attempted to use an interpreter that doesn't exist:
If you instead run the script like this, then the path likely doesn't matter:
That's because you're running python directly, and passing it an argument. Python then decides to open that file and treat it as a script. In the first case, the kernel is attempting to run the script as an executable. It checks it, notices shebang line, and attempts to convert it to the second form, so it can actually run it. That fails if the path given after |
||||
|
|
|
Shebang is a combination of the following characters:
|
||||
|
/usr/bin/than in/usr/local/bin/. As Guardian said in case of your distribution it may be symlink. In my Gentoo second option will fail, as there is no python and no symlink. Also you could check my answer about recommended shebang for python... – pbm Feb 27 at 21:30/usr/bin/pythonand/usr/local/bin/pythonare valid interpreters on your system. They may or may not be the same. – Keith Thompson Feb 28 at 1:56