First of all, #!
in a shell script is known as shebang or hashbang . It is in the form of a comment (lines started with #
are usually ignored by the shell), but the !
soon follows to indicate which is the executable that will process that script. / p>
When you say:
#!/usr/bin/bash
or
#!/bin/bash
is calling the bash
executable to interpret your script. It could be python or another interpreter.
The problem is that from distro to distro , the place of bash
(or python
, for example) may be different. When you do so:
#!/usr/bin/env bash
is running the env
command with the bash
parameter. Env is used to create a new environment, and the following parameter is the command that will be executed by env
in this environment.
As env
uses the path of the system, bash
will run without you having to define your exact path.
This article sums it up well:
link
Now, it remains to be seen if it is really true that env
will always be /usr/bin
:)