18

What is the purpose of using #!/usr/bin/env <sh|bash|python> shebang compared to #!/bin/bash, #!/bin/sh or #!/usr/bin/python?

Flimm
  • 44,031
Tuminoid
  • 3,932

2 Answers2

10

Some people might use a different python (perl, etc.) than the system one. /usr/bin/env python would run the version configured as the current one, possibly making the script more portable.

On the other hand, reportedly, some systems do not have /usr/bin/env. Also, you cannot use #!/usr/bin/env foo x as a replacement for #!foo x, because foo x will be interpreted as a single argument. So the value of the approach is debatable.

choroba
  • 10,313
0
#!/usr/bin/env python
#!/usr/bin/python

The first one is more portable. source1. source2. source3. I haven't seen Linux a system where it doesn't work. And this is a general statement - /usr/bin/env is often available, other binaries sit around the filesystem wherever they please.

Vorac
  • 317