Why default .bashrc is set to return immediately if not running interactively?

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?


Solution 1:

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