I searched google but couldn't find an answer to this rather simple question. I have a python script that has the hash-bang (#!) on the first line:
#!/usr/bin/python
However, what if this is run on a computer with python in /bin/python or /usr/local/bin/python, or some other place? There has to be a better way to set the interpreter for a shell script. It should be possible to set it via $PATH, as that will know where to find python if it's installed on the system.
Use env.
#!/usr/bin/env python
It's not bulletproof, but it covers more cases than /usr/bin/python.
Use
#!/usr/bin/env python
env
is virtually always in /usr/bin
, and will execute any program in the PATH
.
Some people prefer to start with:
#!/usr/bin/env python
Not sure that this is a vast improvement as you're now assuming that python is in the path and that it's the right version, but it's an option.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With