1. Environment variable configuration file

There are two shell modes in Linux: LOGIN shell and NON LOGIN shell. The logic for obtaining the configuration file is different in the two modes.

A. SHELL in login mode is the first process in the user process. The /usr/login is used to read the /usr/passwd file. Echo $0 if -bash is printed, the shell is in login mode.

Can through the su – | | su su – l USERNAME – operations such as creating a login shell.

Load environment variables in login mode shell in the following order.

Bashrc is loaded by ~/.bash_profile /etc/bashrc # is loaded by the ~ /.bashrc callCopy the code

B. Non-login mode SHELL starts through a program and does not login. Echo $0 if bash is printed to indicate that the shell is in non-login mode.

By su | | graphic terminal to perform operations such as creating a script for login shell.

Load order in non-login mode SHELL.

Bashrc is loaded by a non-logged-in SHELL processCopy the code

2. Set the validity range of environment variables in the script. Exporting an environment variable in a script is equivalent to defining an environment variable in the child process. However, this environment variable only takes effect in the child inheritance and does not affect the parent process. You need to use either. *.sh or source *.sh to cause the script to execute in the current process, so that any environment variables defined in the script will affect the current process.