In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the example analysis of the environment variable configuration file in Linux, which is very detailed and has a certain reference value. Interested friends must read it!
The environment variable is closely related to Shell, and a Shell is launched after the user logs in to the system. For Linux, it is usually bash, but you can reset or switch to another Shell. For UNIX, it could be CShelll. The environment variable is set by the Shell command, and the set environment variable can be used by all the programs running by the current user. For the Shell program bash, you can access the corresponding environment variables through the variable name and set the environment variables through export.
one。 System level:
1) etc/profile: this file sets environment information for each user of the system and is executed when the user logs in for the first time. And collect shell settings from the configuration file in the / etc/profile.d directory.
Note: here we set global variables that are available to all users.
2) / etc/bashrc: execute this file for each user running bash shell. When bash shell is opened, the file is read.
two。 User level (these files are in the home directory):
1) ~ / .bash_profile: each user can use this file to enter shell information dedicated to their own use. When the user logs in, the file is executed only once! By default, he sets some environment variables and executes the user's .bashrc file.
Note: under LINUX, it represents the variable HOME.
In addition, under different LINUX operating systems, this file may be different, it may be one or more of ~ / .bash_profile; ~ / .bash_login or ~ / .profile, if there are several, then the order of execution is: ~ / .bash_profile, ~ / .profile, ~ / .profile. For example, if I use Ubuntu, the default file under my user folder is ~ / .profile.
2) ~ / .bashrc: this file contains bash information specific to your bash shell, which is read when you log in and every time you open a new shell.
(note: this document is. At the beginning, so it is hidden in the folder)
So how do we add our own defined environment variables?
Open the file in notepad and write it down at the end of it:
Xiaokang=kangkang
Then save it so that every time you open a new terminal, our variable takes effect. Remember, if you have opened a terminal and you have modified the file, it will not take effect under this terminal. In general, it is best for users to make changes here, but sometimes the parent variables are overridden, such as PATH is set by ROOT, but if you write PATH=xx in this file, then all PATH will become xx in the future, so we should write as follows in this file:
PATH=$PATH:xx
In this way, you add the original with your own. And note that in LINUX systems, use: split to represent juxtaposition, rather than windo's
Both 3 and 4 are in the user directory, and the only difference between them is that .bash _ profile can only be started once when logging in. This 3 file doesn't seem to be available in my Ubuntu.
3) ~ / .bash_logout: execute this file every time you exit the system (exit bash shell).
In addition, the variables (global) set in / etc/profile can act on any user, while the variables (local) set in ~ / .bashrc and so on can only inherit the variables in / etc/profile, they are / "parent-son /" relationship.
~ / .bash_profile is interactive and login enters bash to run.
~ / .bashrc is entered into bash by interactive non-login.
Usually the settings are roughly the same, so the former usually calls the latter.
Through the introduction of the above file, we can understand what files need to be modified when we need to set environment variables, and in order to be effective for all users, we need to set system-level environment variables. Instead, you need to modify the user-level file (preferably the .profile file, for the reasons mentioned above).
In addition, summarize their implementation methods:
When you log in and the login shell is bash, bash first executes the command in the / etc/profile file (if the file exists), then it sequentially looks for the ~ / .bash_profile,~/.bash_login or ~ / .profile file and executes the command in the first readable file found. When bash logs in and exits, it executes the commands in the ~ / .bash_logout file.
When an interactive bash is started, it executes the commands in the ~ / .bashrc file (if the file exists and is readable). When starting non-interactively to run a shell script, bash looks for the bash_env environment variable to determine the name of the execution file.
The above is all the contents of the article "sample Analysis of Environment variable profile in Linux". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
Note: ipaddr (IP address) netmask (subnet mask) gateway (gateway address)
© 2024 shulou.com SLNews company. All rights reserved.