What is the recommended options in bash's shebang?

#!/bin/bash -e

I currently have it as above. This sources $HOME/.bashrc.

I don't want to source user's .bashrc/.profile as it might interfere with the script and it will delay the startup of the script (home directory is usually located in network drive).

Is there some command line option that disables this?
And what are the other recommended flags to put in?

2 Answers 2


You just need to make sure that BASH_ENV is not set. From the INVOCATION section of bash(1):

       When bash is started non-interactively, to  run  a  shell  script,  for
       example, it looks for the variable BASH_ENV in the environment, expands
       its value if it appears there, and uses the expanded value as the  name
       of  a  file to read and execute.  Bash behaves as if the following com‐
       mand were executed:
              if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi
       but the value of the PATH variable is not used to search for  the  file

Other dot files (~/.bash_profile, ~/.bash_logout, etc.) are read when the shell is started interactively.

Unfortunately, you cannot control the environment from the script, even using #!env (which requires only one argument, in this case the shell program, bash). The best you could possibly hope for is to clear out the environment within the script or wrapper and starting with a clear environment, which may not be what you want.

  • How to clear the environment within the script?
    – balki
    Feb 14, 2012 at 6:25
  • If you want to clear everything: eval `env | awk -F= '!/^\t/{print "unset", $1, ";"}'`; but you might want some variables: eval `env | awk -F= '!/^\t/&&$1!~/^(SHELL|PATH|TERMCAP|TERM|HOME|USER|LANG|DISPLAY|XAUTHORITY)$/{print "unset", $1, ";"}'`; otherwise things like $PATH, $DISPLAY and $TERM are removed and need to be reassigned. Some programs do not operate well without the others.
    – Arcege
    Feb 14, 2012 at 7:14

Just read a bit "man bash".

Under the "INVOCATION" section, you would find that the "--noprofile" or "--norc" options should do the trick.

You must log in to answer this question.

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