Get the App
SLTechnology News&Howtos  ›  Servers  › 

The usage of linux shell (()) double bracket operator

Shulou Source: shulou.com Published: 2022-06-01 11:16:19 09月29日 Update

This article introduces the knowledge of "the use of linux shell () double parenthesis operator". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

How to use it:

Syntax:

(expression 1, expression 2... ))

Features:

1. In the double parenthesis structure, all expressions can be like the c language, such as: axioms, expressions, etc.

2. In the double parenthesis structure, all variables can not be prefixed with the "$" symbol.

3. Double parentheses can be used for logical operation and four operations

4. The double parenthesis structure extends the for,while,if conditional test operation.

5. Support multiple expression operations, which are separated by ","

Examples of use:

Extended four operations

The code is as follows:

#! / bin/sh

Axi1

Bread2

Cedar 3

((a=a+1))

Echo $a

Axiom $((axi1rementhmum)

Echo $a _

Running result:

Sh testsh.sh

two

3,3,4

Multiple expressions are supported between double parenthesis structures, and then common c language operators such as addition, subtraction, multiplication and division are supported. If the double parentheses are marked with: $, you will get the expression value and assign it to the left variable.

Extended logic operation

The code is as follows:

#! / bin/sh

Axi1

B = "ab"

Echo $(a > 1x 8vl 9)

((baked = "a")) & & echo "err2"

(a)

Tags: Operations parentheses expressions operators structure logic code results support four operations between content variables four multiple more knowledge language run practical Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Apple OPPO Reno Shulou Technology Linux