Shell in parentheses summary: {}, (), (()), [], [[]]

Source: Internet
Author: User
Tags builtin

Parentheses Summary() Single parenthesis
    • Command group, the command in parentheses will open a new child shell execution

      • Variables in parentheses cannot be used by left script

      • Semicolon separated between commands

      • There can be no space between the command and the parentheses

    • Command substitution, equivalent to ' anti-quote '

      • $ (XXX) will be replaced with command execution results

    • Initializing an array

      • Arr= (a B c d)

FileNum=$ (ls | wc-l) 
${filenum}
FileNum=' ls | wc-l ' 
${filenum}
?
Arr= (a b c d)
${arr[0]}  //a
${arr[@]}  //4
(()) Double parenthesis
    • Integer calculation, floating point not supported

      • ((TMP=A+B))

      • c=$ ((a+b))

    • Comparison of arithmetic operations

((c=2+1))    
    3
D=$ ((1+2)) 
    3
?
a= =true 
if ($a= =   Then
    "A==1"
Fi
/a= =true  
if ((a= =  Then
    "A==1"
Fi
[] Single bracket
    • Judgment command: The General argument is a comparison expression

      • Returns an exit status code based on the results of the comparison

      • The available comparison operators are:

        • String: = =,! =

        • Integers:-eq,-gt,-lt,-ne,-ge,-le

        • Logic:-A (| |),-O (&&)

= = AA
Then
    "AA = = AA"
Else
    "AA! = AA"
Fi
1 < 2
Then
    "1 < 2"
Fi
= = BB
Then
    "1-lt 2-o aa = = BB"
Fi
[[]] double brackets
    • Keywords in bash program language, payment in double brackets does not occur parameter extension or command substitution

    • Support for string pattern matching and regular matching

    • Support logic judges: &&, | |, <, >

Hello and Hell? You can add parentheses, or do not add
Then
    "Hello = = Hell?"
Fi
Then
    "2 > 1 && Hello = = Hell?"
Fi
{} curly braces
    • Use wildcards to extend curly brace content

      • Whitespace is not allowed (unless whitespace is referenced or escaped)

    • Code block:

      • Will not open a new shell, variables can be used by the rest of the script

      • Every command must have a semicolon.

      • There are spaces on both sides of parentheses

' Touch {1..4}.txt '  4.txt
' Touch {ex1, ex2}.txt '  touch ex1.txt ex2.txt

Shell in parentheses summary: {}, (), (()), [], [[]]

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.