Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the difference between braces, braces and curly braces in shell

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "what is the difference between small brackets, middle brackets and curly brackets in shell". The explanation in this article is simple and clear, easy to learn and understand. Please follow the idea of Xiaobian and go deep into it slowly to study and learn "what is the difference between small brackets, middle brackets and curly brackets in shell"!

1. parenthesis, parenthesis () 1. single parenthesis ()

A command group. The command in parentheses will create a new subshell order of execution, 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 may not have a semicolon. There need not be spaces between commands and parentheses.

Order replacement. Equivalent to `cmd`, the shell scans the command line once, finds the $(cmd) structure, executes cmd in $(cmd) once, gets its standard output, and then puts this output into the original command. Some shells are not supported, such as tcsh.

It is used to initialize the array. array=(a b c d)

2. Double parenthesis (( ))

1 Integral extension. This extended calculation is an integer calculation and does not support floating point calculations. The ((exp)) construct extends and evaluates an arithmetic expression that returns an exit status code of 1 or false if the result is 0, whereas a non-zero expression returns an exit status code of 0 or true. If the expression exp is true, it is 1, and if it is false, it is 0.

② As long as the operators and expressions in parentheses conform to the operation rules of C language, they can be used in $((exp)), or even ternary operators. For different carry (such as binary, octal, hexadecimal) operations, the output results are automatically converted to decimal. For example: echo $((16#5f)) The result is 95 (16 base to decimal)

③ Simply using (( )) can also redefine variable values, for example, a=5; ((a++)) can redefine $a to 6

④ Often used for arithmetic comparison, variables in double brackets can be used without the $sign prefix. Multiple expressions are supported within brackets separated by commas. As long as the expression in parentheses conforms to C language operation rules, for example, you can directly use for(i=0;i

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report