Get the App
SLTechnology News&Howtos  ›  Servers  › 

What is the function of (), (), [], [[]], {} in Linux Shell

Shulou Source: shulou.com Published: 2022-05-31 23:56:50 09月23日 Update

This article mainly introduces "what is the function of (), (), [], [], {} in Linux Shell". In daily operation, I believe many people have doubts about the function of (), (), [], [], {} in Linux Shell. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the questions of "what is the function of (), (), [], [[]] and {} in Linux Shell?" Next, please follow the editor to study!

Parentheses, parentheses ()

1. Single parentheses ()

① command group. The command in parentheses will be executed sequentially with a new child shell, so the variables in parentheses cannot be used by the rest of the script. Multiple commands in parentheses are separated by semicolons, the last command can be without a semicolon, and there is no need to have a space between each command and the parentheses.

The ② command is replaced. It is equivalent to cmd,shell scanning the command line and finding the structure, then cmd the structure, then execute the cmd in (cmd) once to get its standard output, and then put this output to the original command. Some shell do not support it, such as tcsh.

③ is used to initialize the array. Such as: array= (a b c d) 2, double parentheses (()) ① integer extension. This extended calculation is integer and does not support floating-point computing. The ((exp)) structure extends and evaluates the value of an arithmetic expression. If the result of the expression is 0, the exit status code returned is 1, or "false", while the exit status code returned by a non-zero expression will be 0, or "true". For logical judgment, the expression exp is 1 if it is true and 0 if it is false. ② can be used in ((exp)) or even trinomial operators as long as the operators and expressions in parentheses conform to the operational rules of C language. When doing different carry operations (such as binary, octal, hexadecimal), the output is automatically converted to decimal. For example, the result of echo ((16,5f)) is 95 (hexadecimal decimal) ③ can also redefine the value of a variable simply with (()), such as axi5; ((axi5f)) can redefine $an as 6.

④ is often used for arithmetic comparisons, and variables in double parentheses do not use symbolic prefixes. Multiple expressions are supported in parentheses separated by commas. As long as the expression in parentheses conforms to the C language operation rules, for example, you can directly use for (

Tags: Commands parentheses patterns characters variables structures expressions strings square brackets results operations semicolons support between right rules actions integers files status Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei MySQL vpn Redmi Shulou Information