Script Portability With env

Table of Contents


Using #!/usr/bin/env#

You can enhance script portability by replacing

#!/bin/bash

with

#!/usr/bin/env bash

and the like.

Always make sure you have /usr/bin/env exists or use a softlink/symbolic link to point it to correct path.

Python Note#

The following taken from Bazaar bug #134046

"#!/usr/bin/env python" which is the appropriate line to use for source installations but it is not the right line to use for system installations. A system tool requires the system python, not the first python on your $PATH. This breaks for everybody who develops Python or has another python on their $PATH.

No system tool ever should use "#!/usr/bin/env python" and in fact setuptools/distutils style packages always rewrite these lines to use a specific version of Python (whichever one the package was installed with). For basic Ubuntu system packages, this should always be "#!/usr/bin/python".

Note that you want your packager to do the right thing here. Just tweaking that line in the source code repository isn't right either because then it will be broken for bzr developers using and testing different python's than the system one.


CategoryComputing.Linux.Shell - CategoryComputing.Mac.Shell