Determine if b.txt This file exists, there is output 1, there is no output 0
[-F B.txt]&& echo 1| | Echo 0
-F: Determines whether the file is
-E: Determine if the file exists
-D: Determine if the directory
-R: Judging whether it is readable
-W: Determine if writable
-X: Determine if executable
Double quotation marks are required to test a single file or directory variable to avoid errors
file=/etc/services[-F "$file"]&& echo 1| | Echo 0
Conditional expression judgment condition after executing multiple command statement wording
#!/bin/bash[$1-eq 2]&&{echo "true"}| | {echo "false"}# && executes the following statement after it is established; | | Do not set up to execute the following statement # If the input value equals 2 print true# otherwise print false#sh test.sh 2: Print True
Common String test operators:
-Z "string" |
True if string length is 0 |
-N "String" |
True if string length is not 0
|
"String 1" = "String 2" |
String 1 equals string 2 is True
|
"String 1"! = "String 2" |
String 1 is not equal to string 2 is True |
Ps:
①, the string test operation symbol in the table above must be caused by ""
②, compare symbols must have spaces at both ends
#字符串长度为0所以输出1 [-N ""]&& echo 1| | Echo 0
Description of the Shell's conditional expressions