Brackets
Brackets are divided into single brackets [] and double brackets [[]]. Square brackets are generally used in expression judgment, and parentheses can also be used in expressions, which will be mentioned later.
Single square brackets []
A=5 B=3 [ $A -eq $B ] 判断A是否等于B [ ${A} -eq ${B} ] 作用同上 [ "${A}" -eq "${B}" ] 作用同上
A=ABC [ $A == "ABC" ] 或写成 [ ${A} == "ABC" ] 或写成 [ "${A}" == "ABC" ] [ $A \> "ABC" ]
[ -d ./aaa.sh -a -e ./bbb ] 测试aaa.sh是否为目录并且bbb是否存在,如果都符合则返回真 [ -d ./aaa.sh -o -e ./bbb ] 测试aaa.sh是否为目录并且bbb是否存在,满足一个条件则返回真
We can see some rules for using single square brackets from the above:
There must be a space between the variable and the square bracket
variable There must also be a space between the operator and the operator
Variables can be referenced directly with $, or they can be referenced with ${} and "${}". Although ${} can be used directly, it is recommended to use "${} ", or use $ directly to quote variables
Strings should be enclosed in double quotes
String comparison generally uses == to test whether the strings are the same, and use for size comparison, in a single To compare characters in parentheses for greater than and less than, use transfer > and <. the comparison principle is to compare ascii.>
In addition, you can also use logical operators like -a and -o in single square brackets
Double square brackets [[]]:
A=5 B=3 [[ $A -eq $B ]] 判断A是否等于B [[ ${A} -eq ${B} ]] 作用同上 [[ "${A}" -eq "${B}" ]] 作用同上
A=ABC [[ $A == "ABC" ]] 或写成 [[ ${A} == "ABC" ]] 或写成 [[ "${A}" == "ABC" ]] 或写成 [[ $A == ABC ]] [[ $A > "ABC" ]]The rules for using double square brackets are similar to the rules for using single square bracketsThe greater-than-less comparison of strings between double square brackets does not need to be escaped, and the strings can be quoted without double quotesCan be used inside double square brackets &&, || are used as logical operators You can also do fuzzy matching inside double brackets, use =~Expression 2 can be a regular expression
[[ -d ./aaa.sh && -e ./bbb ]] 测试aaa.sh是否为目录并且bbb是否存在,如果都符合则返回真 [[ -d ./aaa.sh || -e ./bbb ]] 测试aaa.sh是否为目录并且bbb是否存在,满足一个条件则返回真
A=ABC [[ $A =~ "A" ]] 做模式匹配,这个表达式为真 或写成 [[ ${A} =~ "A" ]] 或写成 [[ "$[A]" =~ "A" ]] [[ $A = A* ]] 表达式为真 [[ $A = B* ]] 表达式为假
Single brackets
Brackets
[ 表达式1 -a 表达式2 ] 等效于 [[ 表达式1 && 表达式2 ]] 等效于 [ 表达式1 ] && [ 表达式2 ] 等效于 [[ 表达式1 ]] && [[ 表达式2 ]]The most common usage is to use it in command substitution. Backticks can also be used for command substitution. ``
[ 表达式1 -o 表达式2 ] 等效于 [[ 表达式1 || 表达式2 ]] 等效于 [ 表达式1 ] || [ 表达式2 ] 等效于 [[ 表达式1 ]] || [[ 表达式2 ]]
Double parentheses
are commonly used in arithmetic operations and also used in for loops
(ls ./;echo "hello";mkdir -p /tmp/ccc)
For statement
1 to 10 Loop execution
echo "当前目录是:$(pwd)" echo "当前目录是:`pwd`"
While statement form
1 to 10 loop
A=$((5+3)) B=$(($A+4))

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Dreamweaver Mac version
Visual web development tools

Dreamweaver CS6
Visual web development tools