Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

A brief introduction to Linux Environment variable File

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "a brief introduction to Linux environment variable files". In daily operation, I believe many people have doubts about the simple introduction of Linux environment variable files. Xiaobian consulted all kinds of information and sorted out simple and easy to use operation methods. I hope to help you answer the doubts of "a brief introduction to Linux environment variable files"! Next, please follow the small series to learn together!

In Linux system, environment variables can be divided into system-level environment variables and user-level environment variables according to their different scope of action.

System-level environment variables: Every user logged into the system can read system-level environment variables

User-level environment variables: Each user logged into the system can only read user-level environment variables belonging to themselves.

Naturally, configuration files for environment variables are divided into system-level and user-level accordingly.

system-level

/etc/profile

Run on the first user login after system startup and gather shell settings from the configuration file in the/etc/profile.d directory. The environment variables configured using this file will be applied to each user logged on to the system.

Tip: On Linux systems, use the following command to make the configuration file take effect immediately.

source /etc/profileecho $PATH

/etc/bashrc (/etc/bash.bashrc in Ubuntu and Debian)

Running with the bash shell open, modifying the environment variables configured in this file will affect all bash shells used by users.

Note: There are different classes of bash shells here, and the environment variable configuration files used by different classes are also different. In general, a non-login shell does not execute any profile files, and a non-interactive shell does not execute any bashrc files.

#Login shell and non-login shell:

Login shell #requires entering the user password, such as ssh login or su -command will start login shell mode

Non-login shell #No user password required;

#Interactive shell and non-interactive shell:

Interactive shell #provides command prompt waiting for user input command is interactive shell mode

Non-interactive shell #Running script files directly is non-interactive shell mode

/etc/environment

Run at system startup, used to configure environment variables related to system operation but not related to users. Modifying the environment variables configured in this file will affect the global situation.

user-level

~/.profile (preferred)

Executed when the user logs in, each user can use this file to configure shell information for their own use.

~/.bashrc

This file will be read when the user logs in and every time a new shell is opened. It is not recommended to configure user-specific environment variables here, because every time a shell is opened, the file will be read once, and efficiency will definitely be affected.

~/.bash_profile or ~./ bash_login

~/.bash_profile or ~./ bash_login - If one of these file exist, bash executes it rather then "~/.profile"when it is started as a login shell. (Bash will prefer "~/.bash_profile" to "~/.bash_login"). However, these files won't influence a graphical session by default.

The above is about ~/.bash_profile and ~./given by ubuntu official website Description of bash_login, translated into Chinese:

~/.bash_profile or ~./ bash_login -

If one of these files exists, Bash will execute that file instead of ~/.profile when launching a login shell;

If both files exist, Bash will give preference to ~/.bash_profile over ~/.bash_login ;

However, by default, these files do not affect graphics sessions

~/.bash_logout

Executes this file every time you exit the system (exit the bash shell).

Note: Linux systems use $VARIABLE_NAME to access environment variables, separating multiple environment variables with: , Windows systems use %VARIABLE_NAME% to access environment variables, separating multiple environment variables with;.

In general, Linux loads environment variable configuration files in the following order:

==> /etc/profile==> ~/.bash_profile | ~/.bash_login |~/.profile==> ~/.bashrc==> /etc/bashrc==> ~/.bash_logout At this point, the study of "A brief introduction to Linux environment variable files" is over, hoping to solve everyone's doubts. Theory and practice can better match to help everyone learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report