Global settings: directly modify/etc/profile (all users take effect)
User settings: Modify ~ /. Bashrc ~ /. Bash_profie (the current user takes effect)
Use the Env command to display all environment variables
Use the SET command to display all locally defined shell Variables
1. environment variables can be set in the command line, but these values will be lost when the user logs out.
For example, to temporarily define the environment variable java_home:
Export $ java_home =/usr/local/JDK
2. How to add environment variables.
Add the following content at the end of the profile file: Export java_home =/usr/local/JDK
OrExport java_home = "/usr/local/JDK" # variable value/usr/local/JDK can be enclosed or not, the effect is the same.
3. The added or modified content in the profile file must be logged out of the system to take effect.
4. Repeated definition of variables
The environment variable with the same name takes effect on the back of the profile file. For example:
The/etc/profile file defines two identical variables: smallke = Good smallke = bad
Unset pathmunge
Export java_home =/usr/local/JDK
Export catalina_base =/usr/local/tomcat
Export catalina_home =/usr/local/tomcat
Export Path = $ catalina_home/bin: $ java_home/bin: $ path
Export classpath = $ java_home/lib
Export smallke = Good
Export smallke = bad
Log out and log on again. Check the output result of smallke.
[Root @ pcmxexweb ~] # Echo $ smallke
Bad
It indicates that the variable samllke = bad is effective.
5. special characters.
For example, if the profile contains the following content, use the following content to describe the usage of special symbols.
Export A =/Q/Jing: AAA/CC/LD
Export B =.:/liheng/Wang
Export A =/CD/CDR: $
: Represents the meaning of the parallel expression. For example, a variable has multiple values and is separated by a symbol.
. Indicates the current directory you are operating on. For example, the PAP command looks for environment variable B.
Type the PAP command in/home. The system first searches for information about B in the/Home Directory (that is, the current path, if no content about B is found in the/liheng/Wang directory.
$ Indicates the value before this definition. For example, $ A indicates/Q/Jing: AAA/CC/lD. That is, a =/CD/CDR:/Q/Jing: AAA/CC/LD
6. Common Environment Variables
Path: determines the directories to which shell will look for commands or programs.
Home: Home Directory of the current user
Mail: refers to the mail storage directory of the current user.
Shell: The shell used by the current user.
Histsize: the number of records that save historical commands.
LOGNAME: The Login Name of the current user.
Hostname: indicates the host name. If a host name is used by many applications, it is usually obtained from this environment variable.
Lang/Languge: it is a language-related environment variable. Users in multiple languages can modify this environment variable.
PS1: A Basic prompt. For root users, it is # And for common users, it is $.
PS2: A subsidiary prompt. The default value is "> ". You can modify this environment variable to modify the current command line. For example, the following command will change the prompt to the string "Hello, my newprompt ".
# PS1 = "Hello, my newprompt"