Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

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
       name.

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.

share|improve this answer
    
How to clear the environment within the script? –  balki Feb 14 '12 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)$/{pri‌​nt "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 '12 at 7:14
add comment

Just read a bit "man bash".

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

share|improve this answer
add comment

Your Answer

 
discard

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.