7

In Ubuntu default .bashrc there's this:

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

Does anyone know why that is there? Is there something in the bashrc that is bad to run if the shell is ran non-interactively?

| improve this question | | | | |
5

The point of the .bashrc file is that it sets the shell up to be more convenient for interactive users. Helpful alias, pretty colors, useful prompts, common environment variables, that sort of thing.

And some of these conveniences could break non-interactive scripts. For example:

`alias rm='rm -i'`

Would not work non-interactively (thanks zwets).

| improve this answer | | | | |
  • What I don't understand: If bash is not started as an interactive shell, then .bashrc isn't read, anyway, is it? I put the line echo ".bashrc is being sourced" in my .bashrc before the [ -z "$PS1" ] && return and then ran bash -c "echo" and is does not show... – Stefan Hamcke Oct 26 '18 at 16:03
  • Okay, I could of course do bash -c "source ~/.bashrc", then it IS sourced :-) – Stefan Hamcke Oct 26 '18 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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