bash - How to use double or single brackets, parentheses, curly braces -


I have brackets in bass, brackets, curly braces, as well as their double or single forms. Is there any explanation?

In Bash, test and [ Biltin Are there.

Enables additional functionality, for example, instead of and you -a and -o And there is a regular expression matching operator = ~ .

Braces, except for marginalizing a variable name, is used so that you can do the following:

  • Break the content of a variable

    $ var = "abcde"; Encoded $ {var% d *}
    ABC

  • create a similar replacement for sed

    $ var = "abcde"; $ {Var / de / 12}
    abc12

  • Use a default value

    $ default = "hello"; Unset var; Copy $ {var: - $ default}
    Hello

  • and many more

  • < In addition to this, the brace extension lists the strokes that generally run in the loop:

      $ echo f {oo, ee, a} d food feed crank $ Mv error log {,. OLD} (error.log has been changed to error.log.old because the brace expression extends for "mv error.log error.log.OLD") for $ {000..2}; Echo "$ Num"; 000 001 002 Resonance {00..8..2} 00 02 04 06 08 $ Resonance {D..T.4} DHLPT  

    Note that leading zero and increase

    Thank you for gboffi to remind me about the brace detail.

    The double bracket is used for:

      ((A ++)) ((for meaning = 42)) ((i = 0; i & Lt; 10; i ++)) $ echo ((a + b + (14 * c))  

    and they release dollar signs on integer and array variables Also include spaces around operators for readability.

    The single bracket is also used for the index:

      array [4] = "hello" element = $ {array [index]}  

    For the simplest references to the right (most / all?) Crisp brace is necessary.

    The confirmation comment reminds me that brackets are also used for subclasses. And that they are used to make arrays.

      array = (1 2 3) echo $ {array [1]} 2  

Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -