Setting environment variables and paths in Linux
After the shell runs, many variables are automatically set, which can be modified and added through the command line. The most important variables are path, LD_LIBRARY_PATH, and include.
A string is stored in the Variable. You can use the echo command to view the content of the variable. The usage is as follows:
[hjk41@Redhat hjk41]$ echo $PATH
/bin:/usr/local/bin:/usr/bin:/usr/X11R6/bin
Note that there is a "$" in front of the path ". We can see that many directory names are stored in the path, which are separated by colons.
When we execute the command, shell will read the content in path, and then go to each directory in sequence to find the executable file. Once found, it will execute the executable file and return it. For example, if we enter "ls", we can find the executable file named "ls" in/bin. Then shell will execute this file and return
LD_LIBRARY_PATH stores the directory of the dynamic link library, while include is the directory of some header files. These two variables are mainly used in programming.
It is easy to set environment variables. You only need to use the Export command. The usage is as follows:
[hjk41@Redhat hjk41]$ export PATH=$PATH:/home/hjk41/bin
[hjk41@Redhat hjk41]$ echo $PATH
/bin:/usr/local/bin:/usr/bin:/usr/X11R6/bin:/home/hjk41/bin
Note the "$" usage here. Write path refers to the variable path, while write $ PATH refers to the string pointed to by the variable path, that is, "/bin:/usr/local/bin: /usr/bin:/usr/x11r6/bin ". Therefore, the first command sets the PATH variable as a new string. The first part of the string is the old path string, followed by the new string ":/home/hjk41/bin ".
If the name of the variable following the export is not set, shell regards it as a new variable. For example: