1. Determine the result of a command using test, which returns 0, or an integer. Returns 0 for true, returns an integer indicating the error code
2. Get the return result of the previous command using $?
3. For example
My server has/home/www such a folder, so ls/home/www The return result of this command is 0;
That is, echo $? Returns a value of 0
My server does not exist/home/kkk such a folder, so ls/home/kkk the return of this command is the command after the execution of the error code;
That is, echo $? Returns a result of 2. This 2 indicates that the file or folder does not exist.
4. Commonly used file test characters
-E Indicates whether this file name exists
-F Indicates whether this filename is a file
-D Indicates whether this file name is a folder
-R Indicates whether this file name is readable
-W Indicates whether this file is writable
-X Indicates whether this file is executable
-S Indicates whether this file asks the socket
4.1/home/www to a folder on my server
So the result of Test-e/home/www is 0, which is true, this file name exists
So the result of Test-f/home/www is not 0, which is false, this filename is not a file
So the result of Test-d/home/www is 0, which is true, this file is named folder
4.2/HOME/KKK This file name does not exist on my server
So the result of Test-e/home/kkk is not 0, which is false, this file name does not exist
So the result of test-d/home/kkk is not 0, which is false, this file name does not ask the folder.
Logical test of Linux basic commands one