-
Tests supported by [ (also known as test):
-
-e FILE: True if file exists.
-
-f FILE: True if file is a regular file.
-
-d FILE: True if file is a directory.
-
-h FILE: True if file is a symbolic link.
-
-p PIPE: True if pipe exists.
-
-r FILE: True if file is readable by you.
-
-s FILE: True if file exists and is not empty.
-
-t FD : True if FD is opened on a terminal.
-
-w FILE: True if the file is writable by you.
-
-x FILE: True if the file is executable by you.
-
-O FILE: True if the file is effectively owned by you.
-
-G FILE: True if the file is effectively owned by your group.
-
FILE -nt FILE: True if the first file is newer than the second.
-
FILE -ot FILE: True if the first file is older than the second.
-
-z STRING: True if the string is empty (it's length is zero).
-
-n STRING: True if the string is not empty (it's length is not zero).
-
STRING = STRING: True if the first string is identical to the second.
-
STRING != STRING: True if the first string is not identical to the second.
-
STRING < STRING: True if the first string sorts before the second.
-
STRING > STRING: True if the first string sorts after the second.
-
EXPR -a EXPR: True if both expressions are true (logical AND).
-
EXPR -o EXPR: True if either expression is true (logical OR).
-
! EXPR: Inverts the result of the expression (logical NOT).
-
INT -eq INT: True if both integers are identical.
-
INT -ne INT: True if the integers are not identical.
-
INT -lt INT: True if the first integer is less than the second.
-
INT -gt INT: True if the first integer is greater than the second.
-
INT -le INT: True if the first integer is less than or equal to the second.
-
INT -ge INT: True if the first integer is greater than or equal to the second.
-
-
Additional tests supported only by [[:
-
STRING = (or ==) PATTERN: Not string comparison like with [ (or test), but pattern matching is performed. True if the string matches the glob pattern.
-
STRING =~ REGEX: True if the string matches the regex pattern.
-
( EXPR ): Parantheses can be used to change the evaluation precedence.
-
EXPR && EXPR: Much like the '-a' operator of test, but does not evaluate the second expression if the first already turns out to be false.
-
EXPR || EXPR: Much like the '-o' operator of test, but does not evaluate the second expression if the first already turns out to be true.
-
Bash ---- [ and [[ memo
最新推荐文章于 2021-05-16 16:10:24 发布