Linux environment variables

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.