What's the difference of using #!/usr/bin/env or #!/bin/env in shebang?
#!<interpreter> <arguments>
tries to run <interpreter> <arguments>
to read and run the rest of the file.
So #!/usr/bin/env
means that there must be a program called /usr/bin/env
;
#!/bin/env
means that there must be a program called /bin/env
.
Some systems have one and not the other.
In my experience, most have /usr/bin/env
, so #!/usr/bin/env
is more common.
Unix systems will try to run <interpreter>
using execve
, which is why it must be a full path, and #!env
without a path will not work.
Mikel explanation is great, it misses just a small fact (which is rather important), it's only one argument being passed including all spaces:
#!<Interpreter> <argument>
Results in calling:
$ <Interpreter> '<argument>' path_to_calling_script
So for Example:
$ cat /tmp/test
#!/usr/bin/env python
print "hi"
$ /tmp/test
is the same as calling:
$ /usr/bin/env "python" /tmp/test
The quotes try to show that if you add any flag or other values will be part of the argument being called.
#!/bin/bash -c /bin/env python
Will be interpreted as:
$ /bin/bash "-c /bin/env python"
Which won't work.