In Linux, environment variables are a very important concept. Environment variables can be set by the system, user, shell, and other programs.
A variable is a string that can be assigned a value, including numbers, text, file names, devices, and other types of data.
In the following example, we will assign a value to the variable TEST and then use the echo command to output:
$TEST="Linux Programming"$echo $TESTLinux Programming
Note: Variable assignment cannot be added before $ symbol, the variable must be prefixed with $. When you exit the shell, the variables will disappear.
After logging in to the system, the shell will have an initialization process for setting environment variables. At this stage, Shell will read the /etc/profile and .profile files as follows:
After reading the above two files, the shell will appear. $ Command Prompt:
$
When this prompt appears, you can enter the command and call the corresponding program.
Note: The above is the initialization process of the Bourne Shell. bash and ksh also check other files during the initialization process.
.profile file
The /etc/profile file contains general shell initialization information, maintained by the Linux administrator, and the general user has no right to modify it.
But you can modify the .profile file in the home directory and add some "private customization" initialization information, including:
Find the .profile file in your home directory and open and view the content using the vi editor.
Set Terminal Type
In general, the terminal we use is set by the login or getty program, which may not meet our habits.
For terminals that have not been used, it may be unfamiliar, not accustomed to the command output style, and it is a little difficult to interact. Therefore, the average user will set the terminal to the following type:
$TERM=vt100$
vt100 is an abbreviation for virtual terminate 100. A virtual terminal is a fake terminal. A terminal that has its own display and keyboard will be connected to the host computer through a special cable (such as a serial port). Vt100 is a virtual terminal specification supported by most Linux systems. Also commonly used are ansi, xterm, etc.
Set PATH variable
When you enter a command at the command prompt, the shell will look up the program corresponding to the command according to the PATH variable. The PATH variable indicates the path where the program is located.
In general, the PATH variable is set as follows:
$PATH=/bin:/usr/bin$
Multiple paths are separated by a colon (:). If the command entered by the user is not found in the path set by PATH, it will report an error, for example:
$hellohello: not found$
PS1 and PS2 variables
PS1 variable is used to save the command prompt , you can modify it at will, if you are not used to using $ as a prompt, you can also change to other characters. After the PS1 variable is modified, the prompt changes immediately.
For example, set the command prompt to ’=>’:
$PS1='=>'=>=>=>
You can also prompt Set to the current directory, for example:
=>PS1="[\\u@\\h \\w]\\$"[root@ip-72-167-112-17 /var/www/tutorialspoint/Linux ]$[root@ip-72-167-112-17 /var/www/tutorialspoint/Linux]$
The command prompt contains the username, hostname, and current directory.
The escape characters in the table below can be used as parameters for PS1 to enrich the command prompt information.
You can change the prompt each time you log in, or you can add the PS1 variable to the .profile file so that the prompt is automatically modified each time you log in.
If the command entered by the user is incomplete, the shell will also use the second prompt to wait for the user to complete the input of the command. The default second command prompt is >, which is saved in the PS2 variable and can be modified at will.
The following example uses the default second command prompt:
$ echo "this is a> test"this is atest$
The following example changes the prompt via the PS2 variable:
$PS2="secondary prompt->"$ echo "this is asecondary prompt->test"this is atest$
Common Environment Variables
The following table lists some of the important Environment variables, which can be modified in the manner mentioned above.
The following example uses some environment variables:
$ echo $HOME/root]$ echo $DISPLAY$ echo $TERMxterm$ echo $PATH/usr/local/bin:/bin:/usr /bin:/home/amrood/bin:/usr/local/bin$
electronic device has two types: radiated noise and conducted noise generated from the power cable a
1. Restart the server2. At the beginning of the boot, enter the boot interface (as shown below) and
This article describes the solution when encountering is not in the sudoers file during Linux use. W
When reading apue, the shared storage area is not used for instance. For this reason, I wrote a smal
Linux port scanning tool nmap use basic tutorial
The initial creation time of the Linux view file is
There are several ways to log in to Linux on Windows platform:
CentOS/RHEL Minimize installation and install setup configuration tool
How to check the shell type used by the Linux operating system
Mathematical calculation summary in the shell
Serial communication study notes under Linux operating system
UNIX system failures and solutions
Linux history: What is the relationship between Linux and GNU?
Win8 version AR9271 network card chip driver (with driver installation method)
How to solve Win10 system 10122 can not activate the problem
Tips big secret interpretation Win7 power button (2)
Windows Phone 7 players can play online in real time
WP8 version of WeChat does not support Didi taxis to grab red packets
Win10 10547 can not play League of Legends and cross the line of fire how to do?
Setting method for using both wired and wireless network cards under Windows XP system
ASUS computer upgrade win10 encountered distortion flashing problem solution (illustration)
What is vi? What does vi mean?
Fun Windows7: Windows 7 and Vista system shortcuts Daquan (3)