当前位置:网站首页>Shell operator, $((expression)) "or" $[expression], expr method, condition judgment, test condition, [condition], comparison between two integers, judgment according to file permission, judgment accor
Shell operator, $((expression)) "or" $[expression], expr method, condition judgment, test condition, [condition], comparison between two integers, judgment according to file permission, judgment accor
2022-07-27 10:04:00 【Redamancy06】
List of articles
- 1. Operator
- 2. conditional
- 2.1 Basic grammar
- 2.2 Common judgment conditions
- 2.2.1 Compare two integers
- 2.2.2 Judge according to the file authority
- 2.2.3 Judge according to the document type
- 2.2.4 test
- 2.2.4.1test condition
- 2.2.4.2[ condition ]( Be careful condition Space before and after )
- 2.2.4.3 stay [] It uses = and !=
- 2.2.4.4-eq be equal to (equal) -ne It's not equal to (not equal)
- 2.2.4.5-lt Less than (less than) -le Less than or equal to (less equal)
- 2.2.4.6-gt Greater than (greater than) -ge Greater than or equal to (greater equal)
- 2.2.4.7 Determine file permissions 、 -r Have read permission (read)、 -w Have the right to write (write) 、 -x Have the authority to execute (execute)
- 2.2.4.8 Determine file type 、-e File exists (existence)、-f The file exists and is a regular file (file)、-d The file exists and is a directory (directory)
- 2.2.4.9 Multi condition judgment (&& Indicates that the previous command is executed successfully , To execute the last command ,|| Indicates the last After a command fails to execute , To execute the next command )
1. Operator
1.1 Basic grammar
“$(( Arithmetic expression ))” or “$[ Arithmetic expression ]”
1.1.1expr Method
use expr Output +、-、*、%
Symbol (+、-、*、%) Space is required on both sides
use * When you need this \, because * There are many uses for , So we need to distinguish

1.1.2 use expr to a assignment
You need to replace
a=$( Arithmetic expression ) Or use a=` Arithmetic expression `

1.1.3$(( Arithmetic expression )) or $[ Arithmetic expression ]

1.1.4 Calculate the sum of two numbers with script

stay add.sh Write the following code in 

2. conditional
2.1 Basic grammar
1)test condition
2)[ condition ]( Be careful condition Space before and after )
Be careful : If the condition is not empty, it is true,[ atguigu ] return true,[ ] return false.
2.2 Common judgment conditions
2.2.1 Compare two integers
-eq be equal to (equal) -ne It's not equal to (not equal)
-lt Less than (less than) -le Less than or equal to (less equal)
-gt Greater than (greater than) -ge Greater than or equal to (greater equal)
notes : If it's a comparison between strings , Use the equal sign “=” Judge equal ; use “!=” Judgment is unequal .
2.2.2 Judge according to the file authority
-r Have read permission (read)
-w Have the right to write (write)
-x Have the authority to execute (execute)
2.2.3 Judge according to the document type
-e File exists (existence)
-f The file exists and is a regular file (file)
-d The file exists and is a directory (directory)
2.2.4 test
2.2.4.1test condition

Test whether his output is correct or wrong $? To judge , Output 0 Then the expression is true , Output 1 Expression is false
2.2.4.2[ condition ]( Be careful condition Space before and after )

use [] When , The equals sign inside must be left blank on both sides , Otherwise, it will be recognized as a whole. If the condition is not empty, it is true

When [] There's something in it , It is true , False when there are only spaces , If there is no space before and after, the command will not be found
2.2.4.3 stay [] It uses = and !=

2.2.4.4-eq be equal to (equal) -ne It's not equal to (not equal)
If it's a comparison between strings , Use the equal sign “=” Judge equal ; use “!=” Judgment is unequal

2.2.4.5-lt Less than (less than) -le Less than or equal to (less equal)
Out-of-service < and <=, Because in linux In indicates input redirection 
Can be used in double parentheses (> < >= <= Number )

2.2.4.6-gt Greater than (greater than) -ge Greater than or equal to (greater equal)
Out-of-service > and >=, Because in linux in > Indicates output redirection 
Can be used in double parentheses (> < >= <= Number )

2.2.4.7 Determine file permissions 、 -r Have read permission (read)、 -w Have the right to write (write) 、 -x Have the authority to execute (execute)

2.2.4.8 Determine file type 、-e File exists (existence)、-f The file exists and is a regular file (file)、-d The file exists and is a directory (directory)

2.2.4.9 Multi condition judgment (&& Indicates that the previous command is executed successfully , To execute the last command ,|| Indicates the last After a command fails to execute , To execute the next command )

边栏推荐
- Why do microservices have to have API gateways?
- GO基础知识—数组和切片
- It's great to write code for 32 inch curved screen display! Send another one!
- Food safety | the more you eat junk food, the more you want to eat it? Please keep this common food calorimeter
- Is Damon partgroupdef a custom object?
- 【云原生 • DevOps】一文掌握容器管理工具 Rancher
- 3D修复论文:Shape Inpainting using 3D Generative Adversarial Network and Recurrent Convolutional Networks
- Brush the title "sword finger offer" day03
- 中高级试题」:MVCC 实现原理是什么?
- Overview of PCL modules (1.6)
猜你喜欢

Gbase 8A MPP cluster capacity expansion practice

Shell综合应用案例,归档文件、发送消息

MOS drive in motor controller
[email protected]、$?、env看所有的全局变量值、set看所有变量"/>Shell变量、系统预定义变量$HOME、$PWD、$SHELL、$USER、自定义变量、特殊变量$n、$#、$*、[email protected]、$?、env看所有的全局变量值、set看所有变量

Understand chisel language. 22. Chisel sequential circuit (II) -- detailed explanation of chisel counter: counter, timer and pulse width modulation

Leetcode.1260. 2D grid migration____ In situ violence / dimensionality reduction + direct positioning of circular array

Concurrent thread state transition

一骑入秦川——浅聊Beego AutoRouter是如何工作

Brush the title "sword finger offer" day03

Interview Essentials: shrimp skin server 15 consecutive questions
随机推荐
7/26 思维+dp+后缀数组的学习
Example of ICP registration for PCL
并发之park与unpark说明
QT learning (II) -.Pro file explanation
食品安全 | 无糖是真的没有糖吗?这些真相要知道
圆环工件毛刺(凸起)缺口(凹陷)检测案例
DCGAN论文改进之处+简化代码
【云原生 • DevOps】一文掌握容器管理工具 Rancher
刷题《剑指Offer》day03
2016 outlook
Final examination paper of engineering materials
Review summary of engineering surveying examination
Practice and exploration of overseas site Seata of ant group
Engineering survey simulation volume a
After one year, the paper was finally accepted by the international summit
Towards the peak of life
Gbase 8A MPP cluster capacity expansion practice
Provincial Emergency Management Department: Guangzhou can strive to promote the experience of emergency safety education for children
Summary of engineering material knowledge points (full)
[scm] source code management - lock of perforce branch