In Linux, we found that some commands can be executed in any directory, and there is no prompt to find the command file, which is where the path variable helps us locate it! First, let's take a look at the path variable
[Email protected]/]# echo $PATH/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
We can see that there are directories in the path variable, and separated by semicolons (:), the meaning of these directories is that when we execute a command, the system looks for the command in the directory of the path variable and executes it.
If a command exists in more than one directory, it will be executed first!
If we want to add a '/' directory to the PATH variable, you can use Path= "$PATH":/
[Email protected] etc]# path= "$PATH":/[[email protected] etc]# echo $PATH/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/ local/bin:/usr/sbin:/usr/bin:/root/bin:/
Now in order to verify the function of the path variable we can create a script file in the root directory to see if it can be used directly in other directories! Here is a simple creation of a script file 1.sh
#!/bin/bashecho "succeed!";
Now go to the/etc directory to see if it can run directly
[[email protected]/]# cd/etc/[[email protected] etc]# 1.sh succeed!
Can see the success! This means that when we manage a system, we can create a directory to add our own management scripts, add directories to the environment variables, so that we can use our own script files everywhere
The PATH environment variable for Linux