The parentheses in the shell have their special usage and are summarized as follows:
1. Parentheses after the symbol $
${a} The value of variable A to omit curly braces without causing ambiguity.
The $ (cmd) command is replaced with the result of the shell command cmd output, and the ' cmd ' effect is the same, although some shell versions do not support the $ () Form of command substitution, such as tcsh.
$ (exp) and ' expr exp ' have the same effect, calculating the numeric value of the mathematical expression exp, where exp can be computed as long as it conforms to the rules of the C language, even the three-mesh operator and the logical expression.
2. More than one command execution
(CMD1;CMD2;CMD3) Open a new sub-shell Order execution command cmd1,cmd2,cmd3, each command separated by semicolons, the last command can be no semicolon.
{cmd1;cmd2;cmd3;} In the current shell Order execution command CMD1,CMD2,CMD3, the commands are separated by semicolons, the last command must have a semicolon, the first command and the opening parenthesis must be separated by a space.
for {} and (), the redirection in parentheses affects only that command, and the redirection outside the brackets affects all the commands in parentheses.
3. Special use of double brackets
(()) enhanced use of parentheses, often used in arithmetic operations comparisons . The variables in the double brackets can not use the $ symbol prefix, as long as the expressions in parentheses conform to the C-language operation rules, and multiple expressions are supported by commas.
For example, you can directly use for ((i=0;i<5;i++)), if you do not use double brackets, then for i in ' seq 0 4 ' or for I in {0..4}.
If you can use the IF (($i <5)) directly, if you do not use double brackets, then if [$i-lt 5].
[[]] enhanced square bracket usage, often used for string comparisons . Mainly used for conditional testing, expressions in double brackets can use &&, | |, <, > C language Syntax.
For example, you can use if [[$a! = 1 && $a! = 2]], if you do not apply double brackets, if [$a-ne 1] && [$a! = 2] or if [$a-ne 1-a $a! = 2] .
This article is from the "Cold River Exclusive Fishing" blog, please be sure to keep this source http://iter2012.blog.51cto.com/6873825/1613690
Special usage of shell brackets