Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

bash - Why must I source .bashrc every time I open terminal for aliases to work?

Git was working fine. I have created an alias in Git but the issue is when I tried to reopen the terminal, then I need to run . ~/.bashrc every time in the terminal.

What is the best way I don't need to provide source every time when I reopen the terminal?

What I did? I am trying to add source of the .bashrc file in this file but it is a read-only file. I am not able to add the source of the .bashrc file in this profile.

open /etc/profile

Added the permission to write in the profile as well, still not able to link the source file.

sudo chmod u+w /etc/profile

Profile:

# System-wide .profile for sh(1)

if [ -x /usr/libexec/path_helper ]; then
   eval `/usr/libexec/path_helper -s`
fi

if [ "${BASH-no}" != "no" ]; then
   [ -r /etc/bashrc ] && . /etc/bashrc
fi
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It looks like your terminal emulator is launching bash as a login shell.

If that's the case, it will read /etc/profile for configuration as well as 1 of the following files, if they exist (listed in order of importance) :

  • ~/.bash_profile
  • ~/.bash_login
  • ~/.profile

It will thus ignore your .bashrc file. A correct fix for your situation would be to either configure your terminal emulator to run bash interactively and non-login, or add [ -f "$HOME/.bashrc" ] && source "$HOME/.bashrc" to your ~/.bash_profile

Here is a link to the documentation about which files are loaded depending of the type of shell you are running


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...