h=$ (date +%h) s=$ (date +%s) m=$ (date +%m)
if [$h = = && $m = = && $s = = 10]]
A. bash [] single and double brackets
Basic elements:O
[] Two symbols should be separated by a space aroundO
There is a space between the internal operator and the action variable: such as ["a" = "B"]O
string Comparisons in,> < need to be written \> \< escapedO
[] In the string or ${} variables as far as possible using "" "double quotation marks, to avoid the value does not define a reference and a good way to errorO
[] can use –a–o for logical operationO
[] is a bash built-in command: [is a shell builtin
1. Test-time logic operators
- a |
Logical AND, both sides of the operator are true, the result is true, otherwise false. |
- o |
Logical OR, the operator side is true, the result is true, otherwise false. |
! |
Logical No, the condition is false and the result is true. |
Example: [-W result.txt-
a-W Score.txt]; echo $? Test whether two files are writable
two. bash [[]] both brackets
Basic elements:O
[[]] Two symbols should be separated by a spaceO
There is a space between the internal operator and the action variable: [["A" = "B"]]O
string comparison, can be used directly > < No need to escapeO
[[]] the string or ${} variable will be matched to pattern and metacharacters as long as it is not used as "" double quotes
[root@localhostkuohao]# [["AB" =a*]] && echo "OK"
OKO
[[]] internal can use && | | For logical OperationO
[[]] is the bash keyword:[[is a shell keyword
[ []] other usages are the same as []