Test-judged
See below:
1 Echo " exist " Echo " Not exist "
Determine if/opt/a.txt exists, output exist, otherwise output not exist
Test also has many uses:
- A "file type" judgment about a file name, such as TEST-E filename indicates whether or not it exists
- -e Whether the file name exists
- -f The file name exists and is a file
- -D whether the file name exists and is a directory
- Permissions on the file, such as Test-f fileName, to determine whether the file is readable
- -R
- -W
- -X
- For a comparison between two files, such as Test file1-nt file2
- -nt (newer than) to determine whether File1 is newer than file2
- -ot (older than) to determine whether File1 is older than file2
- About the judgments between two integers, such as test n1-eq N2
- -eq judgment equals
- -ne judgment is not equal
- -GT N1 greater than N2
- -lt N1 less than N2
- -ge greater than or equal to
- -le less than or equal to
- About string Comparisons
- Test-z String If string is an empty string, returns True
- Test-n String If string is an empty string, returns false
- Test STR1=STR2
- Test STR1!=STR2
- Multiple Criteria Determination
- -A two conditions are also established, such as Test-e file1-a-e file2, to determine whether File1 and file2 are present
- -O Any condition that is set up, such as Test-e File1-o-e file2,file1 or file2 any one presence returns True
- ! Negative, like test! -e File1, indicating that FILE1 does not exist returns true
[ ... ] Judging type
Often used in the judgment of IF statements
Note: Each component in [] must be separated by a space character; the variables are best enclosed in double quotation marks; constants are enclosed in double quotes
Shell script-Judging Type