The difference between. Bashrc and. Bash? Profile


To distinguish the difference between the two, we must first make clearlogin shellandno-login shellThe difference between.

login shell

When you enter the user name and password through the terminal, and then enter terminal, the shell environment you enter is called login shell, for example, throughsshRemote access to the host.

no-login shell

As the name implies, it is a shell environment that does not need to enter the user name and password. For example, if you have logged in to your desktop computer, you can find it in the application managertermianlIcon, and then double-click to open the terminal, that is, through thegnome,KDEThe terminal entered by this desktop environment is the so-called shell environment you enterno-login shellEnvironmental Science. In short, it means that you want to passlogin shellRun the shell command into the.bash_profileI want to passno-login shellRun the shell command into the.bashrcIn the document.


There’s an exception to thisMac OSIn the system, every time you run terminal, the system will run one for you by defaultlogin shellEnvironment, so you seeMac OSSystem~/There is only one in the directory.bash_profileFile without.bashrcDocuments, that’s why.

How to use two files at the same time?

So if I wasMac OSThe system also wants to put some shell commands into the.bashrcWhat about the file? Of course, it’s not recommended. It doesn’t make sense. Then you can create a.bashrcDocuments. Then in.bash_profileWrite the following code in the file:

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

Read at terminal.bash_profileIt will load after the file.bashrcContents of the file.

Original link