For example, in a script you export $KKK=111, if you use./ a.shh to execute the script, after execution, you run echo $KKK and find no value. If you use source to execute, and then echo, you will find KKK=111. Because calling./ a.shh to execute the shell is run in a subshell, so after execution, the structure does not reflect in the parent shell, but the source is different, it is executed in this shell, so you can see the result
when you first login to Linux, first start /etc/profile, then start one of the ~/.bash_profile, ~/.bash_login, or ~/.profile files in the user directory.
The order of execution is: ~/.bash_profile, ~/.bash_login, ~/.profile.
If the ~/.bash_profile exists, the ~/.bashrc file is also typically executed.
if [-f ~/.bashrc];
if [-f ~/.bashrc]; Then
.. /bashrc
fi
~/.bashrc, generally there will be the following code:
if [-f /etc/bashrc]; Then
. /etc/bashrc
fi
so ~/.bashrc will call /etc/bashrc file. Finally, the ~/.bash_logout file is also executed when the shell exits.
execution order: /etc/profile-& gt; (~/.bash_profile | ~/.bash_login | ~/.profile) -> ~/.bashrc -> /etc/bashrc ->
(1) /etc/profile: this file sets the environment information for each user of the system and executes when the user logs in for the first time. And collect shell Settings from the configuration file in the /etc/profit.d directory.
(2) /etc/bashrc: execute this file for every bash shell user. When the bash shell is opened, the file is read (that is, bashrc is executed every time a new terminal is opened).
(3) ~/.bash_profile: each user can use this file to enter shell information dedicated to their own use. When the user logs in, this file is only executed once. By default, some environment variables are set to execute the user’s.bashrC file.
(4) ~/.bashrc: this file contains bash information dedicated to your bash shell, which is read when you log in and every time you open a new shell.
(5) ~/.bash_logout: this file is executed every time the system exits (bash shell). In addition, variables set in /etc/profile (global) can be applied to any user, while variables set in ~/.bashrc (local) can only inherit from variables in /etc/profile, they are “father and son” relationship.
(6) ~/.bash_profile: interactive, login into bash running ~/.bashrc: interactive, non-login into bash running usually the Settings are about the same, so usually the former calls the latter.
The use of various environment variables such as /etc/profile and /etc/environment Settings files
1) First add export LANG=zh_CN to /etc/profile, log out of the system and log in again. The login prompt shows English.
2) First delete export LANG=zh_CN in /etc/profile, add LNAG=zh_CN to /etc/environment, log out of the system and log in again. The login prompt shows Chinese.
user environment is always created by executing /etc/profile before reading /etc/environment. Why is this different?Instead of executing /etc/environment first and /etc/profile later?
this is because: /etc/environment is the environment for setting the whole system, while /etc/profile is the environment for setting all users, the former is irrelevant to the logon user, while the latter is relevant to the logon user.
system application execution environment with users can be independent, but related to the system environment is, so when you log in, you can see, such as date, time, information display format and LANG is related to the system environment, the default LANG = en_US, LANG = zh_CN if the system environment, the message is in Chinese, or in English.
for the user’s shell initialization is to execute /etc/profile first, then read the file /etc/environment; For the whole system, /etc/environment is executed first. Is that correct?
logon order should be
/etc/enviroment –> /etc/profile –> $HOME/.profile –> $HOME/. Env (if present)
/etc/profile is the environment variable for all users
/etc/enviroment is the environment variable for the system
login system the order that the shell reads should be
/etc/profile-& gt; /etc/enviroment –> $HOME/.profile –> $HOME/.env
the reason should be the difference between the user environment and the system environment. If the same variable has different values in the user environment (/etc/profile) and the system environment (/etc/environment), then the user environment should be used as the criterion.
Read More:
- The Linux terminal appears bash: setup.bash : no such file or directory, and. Bashrc file
- bash: /opt/ros/kinetic/ setup.bash : there is no file or directory
- When installing ROS: bash / opt / ROS / kinetic/ setup.bash : there is no file or directory
- Browser prompt: Source mapping error: request failed with status 404 Source URL: http://xxx.js Source mapping URL: jquery.min.map
- How to Fix Error accessing PRODUCT_USER_PROFILE
- Flume profile case (Port listening)
- Error:Failed to create provisioning profile. – iOS
- iOS Xcode:Failed to create provisioning profile.
- Error found when loading /etc/profile when ubuntu18.04 is booted
- File C:\Users\admin\Documents\WindowsPowerShell\profile.ps1 cannot be loaded because running scripts
- Shell script running error bash: JPS: command not found
- User defined profile in vscode settings.json And default configuration defaultSettings.json
- Git bash error, version 2.16.2-64-bit
- Error BC: command not found when git bash runs shell script
- Resolve – bash: fork: Retail: resource temporarily unavailable error
- Failed to execute / bin / bash: resource temporarily unavailable
- Aapt2 error: check logs for details
- Git bash here running error: failed to fork child process
- Some file crashing failed, see logs for details
- Git bash Error: Could not fork child process: There are no available terminals (-1)