I. Environment variables
After the user logs on to the Linux system, the operating system is automatically configured with the working environment-language, home directory, mailbox directory, command search path, terminal type, user name, command prompt, and so on. The user's working environment is defined by a series of environment variables. The format is as follows:
environment variable name = value
Environment variables consist of uppercase and lowercase letters, numbers, _, and general capitalization.
Common User Environment variables:
Lang=zh_cn. UTF-8, the language is defined as UTF-8
Homs=/home/zsan, User home directory
Logname=zsan, user name
Path=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/zsan/.local/bin:home/zsan/bin, define the command search path, Bash looks for programs in these paths for user-entered external commands, and then executes, usually bin files
Shell=/bin/bash Defining User Login Bash
Pwd=/home/zsan, dynamically tracks the user's current directory
Second, environment variable operation
displays the user's environment variable in the format of the command env or echo $< environment variable name >
env Display all environment variables
ECHO Displays specific variables: Echo $LANG
set environment variables with command export:
Export < variable name >= value
Such as:
The export lang=c definition language is English.
export hello= "HELLO World", use quotation marks when there are spaces in the value.
export path= $PATH: $HOME, in this example, refers to the value of a variable in the form of a "$ variable name" .
Remove environment variables with unset, such as
Unset HELLO
The concept similar to user environment variables is shell variables, each shell program has its own set of shell variables, user environment variables are exported command shell variables, is a subset of shell variables, shell variables are defined by set , unset deleted. variables defined using the export and set commands are temporary and are not available after the user logs off or restarts the computer. If you want the defined variable to take effect permanently, you usually add the variable to the end of "/etc/profile" or "~/.BASHRC", which takes effect for all users, which works for the user of the directory. Example:
echo "Export histsizw=5000" >>/etc/profile
Linux Users change Environment variables