Recently installed Neovim, and .bash_profile
set the PATH variable, the strange thing is, every time a new SSH client opens a new session, after logging into his account server, located .bash_profile
in the PATH command is not set to take effect, cause I can not start Neovim installed after each login, I also have to look at the manual source .bash_profile
file before you can use nvim command, very boring. This article will explore why.
Try to .bash_profile
set up inside the copy to .bashrc
found after logging PATH variable settings are valid and working Neovim, which shows .bash_profile
the inside of the set at login time has not been source. Why not? I know the crux of the problem in the future, and soon found the answer to that is used to log the account su $USERNAME
issue instructions. If you use the command log in to your account, open the shell is a non-login shell, just .bashrc
inside the settings are source, so .bash_profile
set up inside and it did not take effect.
login/non-login shell 以及 interactive/non-interactive shell
What is a non-login shell? Make it clear this problem, we need to introduce different modes of shell, in order to simplify the problem, only for the Bash shell. login shell and shell are divided into non-login shell; interactive shell may be divided and non-interactive shell.
interactive shell refers to the shell can output or accept input; non-interactive shell can not accept user input, when running script when, in fact, there is a non-interactive shell in a script file is executed. login shell generally refers to a user logs on to the server (user name and password) entered through normal SSH shell; If after entering the login shell, and then open the GUI terminal or execute bash
a command, then open the non-login shell.
Which configuration file is read?
Using interactive login shell when the log is first read and execute /etc/profile
the file command, then find sequential order ~/.bash_profile
, ~/.bash_login
and ~/.profile
the file, and then read from the first file exists and can be read and executed instruction, bash the man page description as follows:
When bash is invoked as an interactive login shell, or as a non-interactive shell with the –login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable
If it is interactive non-login shell, start time, perform the first read /etc/bashrc
, then read execution ~/.bashrc
.
In both cases are the most common.
In the login account you want to make sure that when the .bash_profile
inside configuration to take effect, open the shell must be a login shell. su
Command provides -l
options (equivalent to -
):
-l Simulate a full login. The environment is discarded except for HOME, SHELL, PATH, TERM, and USER. HOME and SHELL are modified as above. USER is set to the target login. PATH is set to
/bin:/usr/bin
. TERM is imported from your current environment. The invoked shell is the target login’s, and su will change directory to the target login’s home directory.
So, when using the login su - USERNAME
can be guaranteed .bash_profile
inside the settings to take effect.