Super User is a question and answer site for computer enthusiasts and power users. 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 would like to know whether it is good practice, according to you, to use this she-bang:

#!/usr/bin/env bash

instead of


This article seems to advocate for the use of /usr/bin/env but when I use it, skepticism appears.

What is your opinion?

share|improve this question
up vote 2 down vote accepted

In practice, #!/usr/bin/env is portable to almost every system that understands #!. It's a useful idiom for invoking a program that could be anywhere in $PATH. If you hard-code the path to the interpreter, your script might not work if you copy it to a different machine.

My general policy is to use #!/bin/sh for scripts that only use portable sh features (i.e., only POSIX features if I only care about modern unices, and only Bourne features if I care about older systems such as older Solaris releases) and #!/usr/bin/env otherwise.

A downside of #!/usr/bin/env is that it doesn't let you pass any option to the interpreter. With some interpreters, this can be worked around by specifying the options as directives instead, or by making the second line be a dual-language snippet that invokes the interpreter when executed by sh and does nothing when executed by the target interpreter. There's a common perl idiom, for instance (useful to pass -T).

share|improve this answer

env is only useful if the script is going to be used on multiple systems where the location of the binaries can vary. If the script is only used on a single system or in a homogeneous network then it's not necessary.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .