Shell acronyms and judgment symbols []
1. The test command is used to detect the file type and compare values. Determine whether a file exists:
[work@www sh]$ test -e file.txt && echo "exist" || echo "not exist" not exist[work@www sh]$
Check whether the-e file exists test-e filename.
-F indicates whether the file exists and is a file
-D whether the file exists and is a directory
-Whether the file B exists and is a block device
-Whether the c file exists and is a character device
Whether the-S file exists and is a Socket File
-P file exists and is a FIFO (pipe) File
-L whether the file exists and is a connection file
Check file permission-r file existence and read permission
-W: whether the file exists and can be written
-Whether the x file exists and has executable permissions
-Whether the u file exists and has the SUID attribute
-G whether the file exists and has the SGID attribute
Whether the-k file exists and has the Sticky bit attribute
Whether the-s file exists and is a non-blank File
Comparison between two files-nt newer than checks whether file1 is newer than file2
Test file1-nt file2
-Ot older than: Determine whether file1 is older than file2
-Ef determines whether the file is the same. It can be used to determine whether the two files point to the same inode on the hard link.
The two integers-eq equal are equal, test n1-eq n2
-Ne not equal is not equal
-Gt greater
-Lt less than is less
-Ge greater than or equal is greater than or equal
-Le less than or equal is less than or equal
Test-z string: determines whether the string is 0. If the string is null, true or test-z string is returned.
Test-n string determines whether the string is not 0. If the string is null, false is returned.-n can be omitted.
Test str1 = str2 is equal
Test str1! = Whether str2 is not equal
Multiple conditions-a are both true, and, test-r file-a-x file: If file has both rx permissions, true is returned.
-O any one is true, or
! Invert
As follows:
#!/bin/bashtest -e pass && echo "file exist"test -f pass && echo "regular file"test -d pass && echo "directory"
2. The use of the [] Judgment symbol [] is basically the same as that of test. [] Each component must be separated by spaces. It is best to enclose variables in quotation marks.
#!/bin/bashname="Bill gates"[ "$name" == "bill gates" ]echo $?
Address: http://blog.csdn.net/yonggang7/article/details/40479141