As far as I know, the interactive shells may be login or not login, and the start up files for them are different.
- If interactive + login shell →
/etc/profilethen the first readable of~/.bash_profile,~/.bash_login, and~/.profile - If interactive + non-login shell →
/etc/bash.bashrcthen~/.bashrc
I want to set some variables every time I use an interactive shell regardless whether it is a login shell or not.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
No, there isn’t. Yes, this is a design defect.
Use the following content in ~/.bash_profile:
if [ -e ~/.profile ]; then . ~/.profile; fi if [[ -e ~/.bashrc && $- = *i* ]]; then . ~/.bashrc; fi
Beware that bash has an even weirder quirk: when it is a non-interactive login shell and the parent process is rshd or sshd, bash sources ~/.bashrc (but not ~/.bash_profile or ~/.profile). So you might want to put this at the top of your .bashrc:
if [[ $- != *i* ]]; then return; fi
See also Difference between .bashrc and .bash_profile and Difference between Login Shell and Non-Login Shell?
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0