Setting Environment Variablesprofile and BASHRC files
/etc/profile: The first file that is used when the operating system customizes the user environment at logon. This file sets the environment information for each user of the system, and the file is run when the user logs on for the first time.
and collect the shell settings from the configuration file of the/ETC/PROFILE.D folder.
/ETC/BASHRC: executes this file for each user executing the bash shell. When the bash shell is opened, the file is read.
~/.bash_profile: Each user can use this file to enter the shell information dedicated to their own use, when the user logs on, the file runs only once! By default, he sets some environment variables, Run the user's. bashrc file. Each user can use the file to enter shell information dedicated to their own use, and when the user logs in, the file runs only once! By default, he sets some environment variables to run the user's. bashrc file.
~/.BASHRC: This file includes bash information dedicated to your bash shell. The file is read when it is logged on and every time a new shell is opened.
~/.profile: The third file to use when you log in. Profile files that each user can use to enter shell information that is specific to their own use. When a user logs on, the file runs only once! By default. He sets some environment variables to run the user's. bashrc file.
/ETC/BASHRC: Execute this file for each user executing the bash shell. When the bash shell is opened. The file is read.
Difference: Changes in/etc configuration file for all the use of the effective. Requires root permission, and changes the hidden file under ~ (that is, $home). Bash_profile and. BASH_RC are valid only for the current user. Their difference starts with the difference between Windows system variables and user variables
watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvz2f0awvtzq==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast ">
differences between profile and BASHRC files
To understand the difference between BASHRC and profile, first make clear what is interactive shell and noninteractive shell, what is login shell and non-login shell.
The interactive mode is where the shell waits for your input and runs the commands you submit. Such a pattern is called interactive because the shell interacts with the user.
This pattern is also familiar to most users: Log in, run some orders, check back. When you sign back, the shell also terminates.
The shell is also capable of performing in the second mode: noninteractive mode. In this mode, the shell does not interact with you, but instead reads the commands that are stored in the file and executes them . When it reads the end of the file, the shell terminates.
BASHRC and profile are used to save the user's environment information, BASHRC is used for interactive Non-loginshell, and profile is used for interactive login shell. There are a lot of BASHRC and profile files in the system, the following are introduced individually:
For example. The export script is best placed under profile, and alias's variables are best placed under BASHRC
adding environment variables to bash configuration files
C_include_path The environment variables (for C header files) and Cplus_include_path(for C + + header files) are the search paths that indicate the header file that is indicated by the two environment variables after the-i-specified path. Search before the system default path.
Library_path indicates the library search path. This environment variable indicates that the path is searched after the path is specified in-l, and the environment variable is used to find the path to the shared library when the dynamic-link library is found during program compilation, for example, to specify the folder of the dynamic-link library that GCC compiles needs.
The ld_library_path environment variable is used to specify a path other than the system default path when a dynamic link library is found during program load execution, and note that the path specified in Ld_library_path is found before the system default path.
timing and sequence of BASHRC and profile operation
Bash runs the/etc/profile script first, and the/etc/profile script runs first/etc/profile.d/*.sh
Bash then runs the. Bash_profile script under the user's home folder, and the. Bash_profile script runs the. BASHRC script under the user's home folder,
The. BASHRC script runs the/ETC/BASHRC script, which assumes that system files and user files change a system variable at the same time, so the user's configuration overrides the system's configuration. Because the user's profile always runs after
At this point, all the environment variables and initialization settings have been loaded.
Bash then calls Terminfo and INPUTRC, completing the terminal properties and keyboard mapping settings.
This variable of path is a special description:
Assuming that Superuser is logged in, path has been set to the following path before/etc/profile is run:
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
Assuming that it is a normal user, path sets the following path before/etc/profile runs:
/usr/local/bin:/bin:/usr/bin
It is important to note that when the user switches and loads variables such as Su--then, suppose the user switches himself, for example, if the root user switches with Su-root, the loaded path is not the same as above.
Accurately speaking. is not always the same. So. In the/etc/profile script. For example the following configuration has been made:
If ["$EUID" = "0"]; Then
Pathmunge/sbin
Pathmunge/usr/sbin
Pathmunge/usr/local/sbin
Else
Pathmunge/usr/local/sbin after
Pathmunge/usr/sbin after
Pathmunge/sbin after
Fi
Assuming that the superuser is logged in, in the/etc/profile.d/krb5.sh script, add the/usr/kerberos/sbin:/usr/kerberos/bin at the front of the path variable search route.
Assume that a normal user is logged in, and in the/etc/profile.d/krb5.sh script, add the/usr/kerberos/bin at the front of the path variable search route.
In the/etc/profile script, the/usr/x11r6/bin folder is added at the end of the path variable
In $home/.bash_profile, the $home/bin folder is added at the end of the path variable
Take root as an example, and finally path will be like this (no other self-defined basis)
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/x11r6/ Bin:/root/bin
Take Gatieme user (normal user) as an example
/usr/kerberos/bin:/usr/bin:/bin:/usr/x11r6/bin:/home/alice/bin
make environment variables effectiveThere's a run time on the run we found. Environment variables under Linux will always take effect the next time the user logs in or enters the shell. However, we are also able to force the loading of the configuration file using the source command, but it is important to note that the source command is only valid for the current shell (terminal) and the source is invalidated after the terminal is closed. Either source or log off again. So set up everyone changes after the cancellation
Linux environment variable specific explanation