Use the parentheses operator linuxshell "()"

Source: Internet
Author: User
The shell () double bracket operator uses four arithmetic operations and logical operations for inuxshell script programming at the beginning. It is estimated that many friends feel unacceptable. When using the special variable logical operator [], there must be a space between the operator and arithmetic. 4...
The linux shell "()" double-bracket operator uses four arithmetic operations and logical operations for inux shell script programming at the beginning. It is estimated that many friends feel unacceptable. When using the special variable logical operator "[]", there must be a space between the operator and arithmetic. The four arithmetic operations can only be completed by using commands such as: let and expr. The double parentheses () structure statement described today is an extension of the arithmetic and value assignment operations in shell. Usage: syntax: www.2cto.com (expression 1, expression 2 ...)) Features: 1. in the double-bracket structure, all expressions can be the same as those in the C language, such as a ++ and B. 2. in the double-bracket structure, all variables can be prefixed with the "$" symbol. 3. you can perform logical operations with double parentheses. 4. the double parentheses structure extends the for, while, and if conditions. 5. multiple expressions are supported. each expression uses ", "Use instances separately: expand the four arithmetic operations #! /Bin/sh a = 1; B = 2; c = 3; (a = a + 1); echo $ a; a = $ (a + 1, B ++, c ++); echo $ a, $ B, $ c running result: sh testsh. multiple expressions are supported between the, and 4 double-bracket structures at www.2cto.com. common operators such as addition, subtraction, multiplication, division, and so on are supported. If the brackets are: $, the expression value is obtained and assigned to the left variable. Extended logical operations #! /Bin/sh a = 1; B = "AB"; echo $ (a> 1? 8: 9); (B! = "A") & echo "err2"; (a <2) & echo "OK"; running result: sh testsh. sh9 www.2cto.com err2ok extended process control statement (logical relationship )#! /Bin/sh num = 100; total = 0; for (I = 0; I <= num; I ++); do (total + = I )); doneecho $ total; total = 0; I = 0; while (I <= num); do www.2cto.com (total + = I, I ++ )); doneecho $ total; if (total> = 5050); then echo "OK"; fi operation result: sh testsh. sh50505050ok has the double-bracket operator [[], [], and test, which can be left to one side by let and expr.

Address: http://www.cnblogs.com/chengmo/archive/2010/10/19/1855577.html #
 
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.