Skip to main content
2 of 5
added 636 characters in body
cuonglm
  • 158.1k
  • 41
  • 341
  • 419

By convention, .bashrc is place where user store the customize configuration for the shell.

These customize configuration can be environment variables, aliases, fancy prompt. With a non-interactive shell, those short of things are meaningless. Moreover, a non-interactive shell can be call in many contexts, you're not sure those environment variables can lead to false negative case, or even security vulnerable.

A closest example is alias. With an alias like:

alias cp='cp -i'

Then it hang your non-interactive shell forever.

So the check perform at the top of .bashrc to ensure that we don't get trouble.


Because the shell can be called as non-interactive login shell, so explicitly block sourcing *bashrc make no sense.

When the shell was called as login shell, it source /etc/profile, then source the first found in ~/.bash_profile, ~/.bash_login, and ~/.profile.

Nothing prevent those file to source .bashrc itself, so doing the check inside .bashrc is safer and make things simple.

cuonglm
  • 158.1k
  • 41
  • 341
  • 419