Preferred Method #! in shell scripts

I searched google but could not find the answer to this rather simple question. I have a python script that has hash-bang (#!) In the first line:

#!/usr/bin/python

However, what if it runs on a python machine in / bin / python or / usr / local / bin / python or another place? There should be a better way to install an interpreter for a shell script. It should be possible to install it via $ PATH, as this will know where to find python if it is installed on the system.

+5
source share
3 answers

Use env.

#!/usr/bin/env python

It is not bulletproof, but it covers more cases than / usr / bin / python.

+12
source

Using

#!/usr/bin/env python

env /usr/bin PATH.

+4

:

#!/usr/bin/env python

Not sure if this is a significant improvement as you now assume that python is on the way and that it is correct, but it is an option.

+3
source

All Articles