1

I see many people do the opposite. Are there any reasons why it is a bad idea to source ~/.profile from ~/.bashrc?

# .bashrc

if [ -f ~/.profile ]; then
    source ~/.profile
fi

I've done a lot of searching and usually people do the following:

# .bash_profile

if [ -f ~/.profile ]; then
    source ~/.profile
fi

if [ -f ~/.bashrc ]; then
    source ~/.bashrc
fi

I need some env variables in ~/.profile to be defined for an interactive shell that is not a login shell (thus I'm using ~/.bashrc). Is this opening me to any dangers?

closed as primarily opinion-based by muru, waltinator, user117103, Videonauth, Charles Green Nov 26 '17 at 14:18

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.

2

Without knowing your .bashrc and your .profile, we can't say. For example, the default .profile on Ubuntu sources .bashrc. Now if you source .profile from .bashrc, you get an infinite loop:

$ bash  
zsh: segmentation fault (core dumped)  bash

(I use zsh, that's why zsh reports the segfault.)

You could place guards that ensure these files get sourced at most once, but who knows what else may interact weirdly?

For your environment variables problem, it depends on how you're starting this interactive non-login shell. Try .pam_environment instead.

  • I see. Why Ubuntu sources .bashrc from .profile? Profile, AFAIK, should be used only for setting env (works with bash and sh). My profile only changes PATH in my example. – user34295 Nov 25 '17 at 15:49
  • askubuntu.com/q/432508/158442 – muru Nov 25 '17 at 15:50

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