Shell Parenthesis Usage Introduction

Source: Internet
Author: User
Tags arithmetic operators

    • Medium brackets [

and the test command equivalent, the user Boolean judgment, such as:

1 a='abc'2if'abc'  ] 3  Then 4    " Yes " 5 Else 6    " No " 7 Fi

Equivalent to

1 if ' ABC ' 2  Then 3     " Yes " 4 Else 5     " No " 6 Fi

When using [], be aware that:

1. [] left and right brackets to leave a space, or will error

2. If the value on the left side of = = is empty, it will cause the command to go wrong, in order to prevent this, usually add an extra string to the left or right, for example:

if [${a}x = = Abcx]

Also, note the difference between the parentheses and the double brackets:

    • Parentheses (

Parentheses are used in arithmetic operators, which are similar to the Let command when used for assignment operations, and are referenced here

Let a=5((a=ten)) echo $a, $b

((a= $a +7))         # Add 7 to a((a = a + 7))      # Add 7 to a.  Identical to the previous command. ((A + = 7))         # ADD 7 to a.  Identical to the previous command. ((a = random% + 1))     # Choose A random number from 1 to ten.                             # is modulus, as in C.   

Double parentheses to the left plus the $ symbol to replace the result, such as:

echo $ (a>)

A single () is used to execute the corresponding command in the new Subshell, such as:

(CD..) /.. /)

It is important to note that this command does not change the current directory after it has been executed

Resources:

Http://mywiki.wooledge.org/ArithmeticExpression

Http://stackoverflow.com/questions/2188199/how-to-use-double-or-single-bracket-parentheses-curly-braces

Shell Parenthesis Usage Introduction

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.