Multi-conditional Process Control for Shell if

Source: Internet
Author: User
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 []
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.