Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I notice that with bash scripts, some people use a different shebang to the one that I'm used to putting at the top of my own.

Can someone simplify the difference between these two? I use the #!/bin/bash one all the time.

#!/usr/bin/env bash
share|improve this question
see unix.stackexchange.com/questions/29608/… and take note of what it says about passing arguments to the interpreter. IMO using /usr/bin/env like this is an abuse of the env program perpetrated mostly by the python community because they can't manage interpreter and library versioning properly. – cas Oct 5 '13 at 5:58
up vote 11 down vote accepted

The #!/usr/bin/env bash results in the script using whatever bash is found first in $PATH.

While it is common for bash to be located at /bin/bash. There are cases where it is not (different operating systems). Another potential use is when there are multiple bash shells installed (newer version at an alternate location like /usr/local/bin/bash).

Doing #!/usr/bin/env bash just takes advantage of a behavior of the env utility.
The env utility is normally used for manipulating the environment when calling a program (for example; env -i someprog to wipe the environment clean). However by providing no arguments other than the program to execute, it results in executing the specified program as found in $PATH.

Note that there are both advantages and disadvantages to doing this.

The advantages are as mentioned earlier, in that it makes the script portable if bash is installed in a different location, or if /bin/bash is too old to support things the script is trying to do.

The disadvantage is that you can get unpredictable behavior. Since you're at the mercy of the user's $PATH, it can result in the script being run with a version of bash that has different behavior than what the script expects.

share|improve this answer
Thank you for the explanation. – Danijel-James W Oct 5 '13 at 2:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.