In one sense, using
env could be considered "portable" in that the path to
bash is not relevant (
~/bin/bash, or whatever path) because it is specified in the environment. In this way, a script author could make his script easier to run on many different systems.
In another sense, using
env to find
bash or any other shell or command interpreter is considered a security risk because an unknown binary (malware) might be used to execute the script. In these environments, and sometimes by managerial policy, the path is specified explicitly with a full path:
In general, use
env unless you know you are writing in one of these environments that scrutinize the minute details of risk.
When Ubuntu first started using
dash, some time in 2011, many scripts were broken by that action. There was discussion about it on askubuntu.com. Most scripts were written
#!/bin/sh which was a link to
/bin/bash. The consensus was this: the script writer is responsible for specifying the interpreter. Therefore, if your script should always be invoked with BASH, specify it from the environment. This saves you having to guess the path, which is different on various Unix/Linux systems. In addition, it will work if tomorrow
/bin/sh becomes a link to some other shell like
Another difference is that the
env method won't allow the passing of arguments to the interpreter.