Why does a shebang need a path?
Wrong
#!ruby
Correct
#!/usr/local/bin/ruby
#!/usr/bin/env ruby
The operating system should have the information regarding the path for a registered command, and why does it still expect it to be given?
|
|
|
Probably to keep the kernel simpler. I don't think the kernel ever searches your path to find an executable. That's handled by the C library. Also, I don't think the kernel has a notion of what your path is. |
|||
|
|
|
You can get
has the semantics you would like from
The reason that depending on
Each level should not assume the existence of binaries later in the sequence, which are more "application" but may rely on binaries earlier, which are more "fundament". And the PATH variable tends to run from applicationy to fundamental, which is the opposite direction to the natural dependency above. To illustrate the problem, ask yourself what happens if a script in There isn't really any other platform-independent "operating system ... information regarding the path for a registered command", so the simplest thing is to insist on the path being provided in the |
||||
|
|
|
I believe that's so you can specify an alternate interpreter if you need or want to. For example:
More often seen with shell scripts:
|
|||||||
|
|
From Classic Shell Scripting book:
|
|||
|
|
|
There are other reasons, but from a security perspective I would never want a script to make assumptions about the correct path. What if it is wrong and it runs the wrong shell or interpreter? One that has been inserted by a malicious user? Or what if it relies on a particular shell and will crash out if the wrong shell is used? Users may mess around with their path and break stuff - don't trust the user:-) I have conducted numerous attacks which rely on the user doing the wrong thing with their path - usually getting things in the wrong order - so I can subvert a normal script call. Yes, I know if you've written the script yourself you can quite rightly claim that you have sorted out your own path, but an interpreter can't make those decisions. |
|||||||||||
|