Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 want my test script could be run without initial startup scripts.

I found the option "--norc" can not work. The bash version is 4.2.0(2)

my ~/.bashrc contains

echo "in .bashrc"

I want to bash --norc -x output a content without .bashrc.

$ touch
$ bash -x
+ echo 'in .bashrc'
in .bashrc

$ bash --norc -x
+ echo 'in .bashrc'
in .bashrc

I found this problem only occurs on my Embedded system. The real Linux does not have such problem.

share|improve this question
Does "echo $BASH_ENV" produce any output? The value of that parameter is used as the name of a file to source even for non-interactive shells; perhaps it is set to ".bashrc" somewhere. – chepner Feb 15 '13 at 18:54
up vote 1 down vote accepted

As I mentioned in my comment, non-interactive shells aren’t supposed to read .bashrc at all.  So your question shouldn’t be “Why is --norc not working?”; your question should be “Why is this shell script (non-interactive shell) reading .bashrc in the first place?”.  One possibility is that you have a BASH_ENV environment variable that is set to ~/.bashrc.  If that’s not it, I don’t know, but here are some things you might want to try:

  • If your script isn’t doing anything bash-specific, try running it with sh; i.e., sh -x
  • Create a testrc file with an echo in it, and say bash -–rcfile testrc -x
  • Say bash -–rcfile /dev/null -x
  • Any and all of the above without -x.  (This shouldn’t make a difference, but this problem already doesn’t make any sense.)
  • Run the script as a normal program: chmod +x and then just (or ./, if you don’t have . in your search path).  (You will need to have #!/bin/bash, #!/bin/sh, #!/usr/bin/env bash, or something equivalent as the first line of, but that’s a good practice anyway –– see grawity’s discussion.)  (But this shouldn’t make a difference, either.)
  • And really, you should do this first, but I didn’t want to annoy you and make you ignore the rest of my answer: Make sure the problem is what you say it is.  Check, double-check, and triple-check for any source or . commands that might (maybe indirectly) pull in .bashrc.  Similarly, see whether it calls any other scripts that might be doing it.  Verify that the in .bashrc message is really coming from .bashrc –– try renaming .bashrc (e.g., to .bashrc.hold, or whatever) and/or chmoding it to 0, and try again.
share|improve this answer
I've simplified my question, so I just use touch to create empty shell script. I've tested all your suggestion before asking. This is very strange. I'm testing it in embedded system. But when I test on Linux box, it seems work. – Daniel YC Lin Feb 17 '13 at 1:20
The major reason is 'BASH_ENV', I unset it, then it works. – Daniel YC Lin Feb 17 '13 at 2:06

--norc only applies to interactive shells; you are starting a non-interactive shell by providing the argument. Try adding the -i flag as well to force an interactive shell. (Note: this may leave you in the new shell after completes; I haven't tested.)

share|improve this answer
That doesn’t make much sense. The reason --norc applies only to interactive shells is that non-interactive shells aren’t supposed to read .bashrc at all. Sure, I’m interested in hearing whether specifying -i fixes the problem, but it seems like a peculiar way to try. – Scott Feb 15 '13 at 18:48
Good point; I missed the forest for the trees. I guess the real question is, why is he seeing output from .bashrc even without --norc. – chepner Feb 15 '13 at 18:52

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.