Linux environment variables
Environment variables: Switch folders and find execution files.
Check the environment variables env and set commands. The differences between the variables searched by set include User-Defined variables and bash interfaces.
Export converts custom variables to environment variables, which can be inherited.
malan@malan-Lenovo-G470 ~ $ name=Bellmalan@malan-Lenovo-G470 ~ $ echo $nameBellmalan@malan-Lenovo-G470 ~ $ bashmalan@malan-Lenovo-G470 ~ $ echo $namemalan@malan-Lenovo-G470 ~ $ exitexitmalan@malan-Lenovo-G470 ~ $ export namemalan@malan-Lenovo-G470 ~ $ bashmalan@malan-Lenovo-G470 ~ $ echo $nameBellmalan@malan-Lenovo-G470 ~ $
Note: bash indicates to enable a new bash process. exit indicates to exit the current bash process.
Environment variables are read from the configuration files of some environment variables, so the environment variables set through export on the door are no longer available after the shell is restarted.
To change the environment variables permanently, you must set the environment variables in the configuration file.
After the environment variable configuration file is modified, the shell must be restarted before it can be re-read. The source command can make the configuration file take effect immediately.
Malan @ malan-Lenovo-G470 ~ $ Source configuration file
Configuration file details
# Distinguish login shell from non-login shell
Login shellNon-login shellYou do not need to log on to the/etc/profile system ~ /. Bashrc ~ /. Bash_profile ~ /. Bash_login ~ /. Profile <user's personal file> only one of the above three files is read, and the priority from the front to the back is
To sum up, you can change the environment variables in your personal files and use source to take effect immediately. For login shell and non-login shell, pay attention to the differences in the configuration files.
Malan @ malan-Lenovo-G470 ~ $ Cat. bashrcmalan @ malan-Lenovo-G470 ~ $ Echo $ namemalan @ malan-Lenovo-G470 ~ $ Echo "export name = Bell">. bashrcmalan @ malan-Lenovo-G470 ~ $ Source. bashrcmalan @ malan-Lenovo-G470 ~ $ Echo $ nameBell restart terminal, still effective