The role of (),(()),[],[[]],{} in linux

The function of (),(()),[],[[]],{} in linux:
ref: http://bbs.chinaunix.net/forum.php?mod=viewthread&tid=1196028&page=1

()

Command group. The list of commands in parentheses will be run as a subshell.
Variables in parentheses, because they are in a subshell, are not available for the rest of the script. The parent process, that is, the script By itself, it will not be able to read the variables created in the subprocess, that is, the variables created in the subshell.
(cmd1;cmd2;cmd3)

Initialize the array.
Array=(element1 element2 element3)

$(…)

Equivalent to a ...command, returns the result of the execution of the command in parentheses

[[ KaTeX parse error: Expected'EOF', got'#' at position 15: a == z* ]] #̲ If a starts with "z" (pattern matching) then the result will be true
[[ KaTeX parse error: Expected'EOF', got'#' at position 15: a == "z*" ]] #̲ If a and z* are equal (which means exactly the same literally), then the result is true.

[ KaTeX parse error: Expected'EOF', got'#' at position 16: a == z*] # ̲ File extension matching (file gl… a" == “z*”] # If $a is equal to z* (It means exactly the same literally), then the result is true.

let command

(( ))

The ((… )) structure can be used to calculate and test the result of arithmetic expressions. The exit status will be completely opposite to the […] structure! It can also be applied to c-style for, while loop statements, (( )), all The variables (it doesn't matter if you add $) are all numeric values.

((...)) Structured expressions are C-style expressions, and the returned result is the expression value, where variable references can be used without '((...)) structured expressions are C-style expressions , The result returned is the expression value, where variable references are not necessary' ( ( . . . ) ) Junction structure of the table of the formula is C air cell of the table of the formula , which returns back to the junction results are tables of type value , which is the variable amount of lead used can not be used ' ' (of course also possible)

for((…;…;…))
do
cmd
done

while ((…))
do
cmd
done

Comparison operator

<

小于 

(("$a" < "$b")) 

<=

小于等于 

(("$a" <= "$b")) 
大于 

(("$a" > "$b")) 

=

大于等于 

(("$a" >= "$b")) 

(( 0 ))
echo “Exit status of (( 0 )) is $?.” # 1

(( 1 ))
echo “Exit status of (( 1 )) is $?.” # 0

(( 5 > 4 )) # 真
echo “Exit status of (( 5 > 4 )) is $?.” # 0

(( 5> 9 )) # Fake
echo “Exit status of (( 5 > 9 ))is $?.” # 1

(( 5 - 5 )) # 0
echo “Exit status of (( 5 - 5 )) is $?.” # 1

(( 5/4 )) # Division is also possible.
echo “Exit status of (( 5 / 4 ))is $?.” # 0

(( 1/2 )) # The result of division calculation< 1.
echo "Exit status of (( 1 / 2 ))is KaTeX parse error: Expected'EOF', got'#' at position 9: ?." # ̲ The result after interception is 0. … ".
do
echo -n "$a "
done

while (( a <= LIMIT )) # Double parentheses, there is no " " before the variable . doecho − n "". do echo -n"".doechon"a "
((a += 1)) # let “a+=1”
done

a=2
b= ( ( (( ((a4)) #a=2 b=8
c=$((a
3)) #a=2 c=6

{xxx,yyy,zzz,…}

Bracket expansion.
echo {1…20}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
cat {file1,file2,file3}> combined_file

Connect file1, file2, and file3 together and redirect to combined_file.

cp file22.{txt,backup}

Copy "file22.txt" to "file22.backup"

In the braces, no white space is allowed unless the white space is quoted or escaped.

echo {file1,file2}\ :{\ A," B",’ C’}

file1: A file1: B file1: C file2: A file2: B file2: C

Code block

This structure actually creates an anonymous function (a function without a name). However, unlike the "standard" function, the variables declared in it are still visible to the code in other parts of the script (except for the use of declare, (variables declared by the typeset command)

() will open a new subshell, {} will not open a new subshell

(()) is often used for comparison of arithmetic operations, and (()) is often used for comparison of strings.

$() returns the result of the command execution in parentheses

The result returned by $(()) is the value of the expression in parentheses

Guess you like

Origin blog.csdn.net/qq_30566629/article/details/109344564