Linux environment variables (2)

  
                  1, linux is a multi-user operating system. Each user logs into the system and has a dedicated runtime environment. Usually the default environment for each user is the same. This default environment is actually a definition of a set of environment variables. Users can customize their own operating environment by modifying the corresponding system environment variables. 2, often modify the environment variables in the /etc/profile file, the content modified here is for all users.
The following main operations will be performed in this file. 3. How to add environment variables.
For example, add "NAME=liheng".
Add the following content at the end of the profile file export NAME=liheng
The variable value liheng can be quoted or not, the effect is the same. 4. The content added or modified in the profile file needs to be logged off to take effect. 5. Repeat how the variables are understood.
What often happens is the definition of the PATH variable.
For example: in the peofile default to the PATH variable has a PATH=¥¥¥¥¥¥¥ (can not remember), in the future may be in the PATH settings, generally added in the profile of the last PATH = · ····· (say an analogy). The PATH=········¥¥¥¥¥¥¥¥¥, which is recognized in the system, means the environment variable of the same name, and the first function of the post-write (commonly speaking). Everyone must pay attention. 6, special characters introduced.
For example, the following contents are included in the profile, and the usage of the special symbols is explained by the following.
export A=/q/jing:aaa/cc/ld
export B=.:/liheng/wang
export A=/cd/cdr:$A
Everyone pays attention to the red symbol:
: Indicates the parallel meaning. For example, there are multiple values ​​of the A variable, and the symbol is used for separation.
. Indicates the current directory of your operation. For example, the pap command will look for the B environment variable.
In the /home type pap command, the system first finds the contents of B in the /home directory (that is, the current path), if not in the /liheng/wang directory to find information about B.
$ indicates the value of this variable before this definition, such as $A for /q/jing:aaa/cc/ld. That is to say
A=/cd/cdr:/q/jing:aaa/cc/ld
7, use the env command to display all environment variables. Just type env at the command prompt.
The set command displays all locally defined shell variables. 8, common environment variables
PATH: determines which directories the shell will look for commands or programs
HOME: current user home directory
MAIL: refers to the current user's mail storage directory.
SHELL: refers to which shell the current user is using.
HISTSIZE: refers to the number of records saved history command
LOGNAME: refers to the current user's login name.
HOSTNAME: refers to the name of the host, many applications are usually obtained from this environment variable if you want to use the host name.
LANG/LANGUGE: is a language-dependent environment variable that can be modified by users in multiple languages.
PS1: is the basic prompt, for the root user is #, for ordinary users is $.
PS2: is a sub-prompt, the default is ">". You can modify the current command character by modifying this environment variable. For example, the following command will change the prompt to the string "Hello, My NewPrompt :) ".
# PS1=" Hello, My NewPrompt :) " 9. Edit the environment variable using the modified .bashrc file, which is only useful for the current user.
Editing environment variables using the modified /etc/profile file is useful for all users. Everyone must pay attention to the difference.
10, the profile file will be run when the system starts. You can add other commands to it, but you must add it correctly. Otherwise, the system will not start up.
Copyright © Windows knowledge All Rights Reserved