First of all, the #!
in a shell script is known as shebang or hashbang. It has the shape of a comment (lines started with #
are usually ignored by the shell), but the !
then serves to indicate which is the executable that will process that script.
When you say:
#!/usr/bin/bash
or
#!/bin/bash
is calling the executable bash
to interpret your script. It could be python or another interpreter.
The problem is that of distro for distro, the place of bash
(or of python
, for example) may be different. When you do so:
#!/usr/bin/env bash
is executing the command env
with the parameter bash
. env serves to create a new environment, and the following parameter is the command that will be executed by env
in this environment.
Like the env
uses the path of the system, the bash
will run without you having to set your exact path.
This article summarizes this (en):
http://www.cyberciti.biz/tips/finding-bash-perl-python-portably-using-env.html
Now it remains to be seen whether it is really true that the env
will always be in /usr/bin
:)