当前位置:网站首页>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 )

边栏推荐
- Provincial Emergency Management Department: Guangzhou can strive to promote the experience of emergency safety education for children
- 吃透Chisel语言.22.Chisel时序电路(二)——Chisel计数器(Counter)详解:计数器、定时器和脉宽调制
- [cloud native • Devops] master the container management tool rancher
- 中高级试题」:MVCC 实现原理是什么?
- Interview Essentials: shrimp skin server 15 consecutive questions
- 吃透Chisel语言.27.Chisel进阶之有限状态机(一)——基本有限状态机(Moore机)
- 刷题《剑指Offer》day04
- 注解与反射
- 食品安全 | 还在吃酵米面吗?当心这些食物有毒!
- Summary of engineering material knowledge points (full)
猜你喜欢

C # set different text watermarks for each page of word

StyleGAN论文笔记+修改代码尝试3D点云生成

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

Concurrent Park and unpark description

WGAN、WGAN-GP、BigGAN

Explain knative cloud function framework in simple terms!

Leetcode.814. binary tree pruning____ DFS

吃透Chisel语言.24.Chisel时序电路(四)——Chisel内存(Memory)详解

Understand chisel language. 25. Advanced input signal processing of chisel (I) -- asynchronous input and de jitter

历时一年,论文终于被国际顶会接收了
随机推荐
Leetcode.565. array nesting____ Violent dfs- > pruning dfs- > in situ modification
Shell的read 读取控制台输入、read的使用
[scm] source code management - lock of perforce branch
吃透Chisel语言.22.Chisel时序电路(二)——Chisel计数器(Counter)详解:计数器、定时器和脉宽调制
3D修复论文:Shape Inpainting using 3D Generative Adversarial Network and Recurrent Convolutional Networks
Explain knative cloud function framework in simple terms!
Gbase 8A MPP cluster capacity expansion practice
TFlite 的简单使用
Is Damon partgroupdef a custom object?
About getter/setter methods
Exercises --- quick arrangement, merging, floating point number dichotomy
Towards the peak of life
原生input标签的文件上传
食品安全 | 垃圾食品越吃越想吃?这份常见食品热量表请收好
Live countdown 3 days sofachannel 29 P2P based file and image acceleration system Dragonfly
食品安全 | 无糖是真的没有糖吗?这些真相要知道
吃透Chisel语言.27.Chisel进阶之有限状态机(一)——基本有限状态机(Moore机)
Summary of engineering material knowledge points (full)
LeetCode.1260. 二维网格迁移____原地暴力 / 降维+循环数组直接定位
c'mon! Please don't ask me about ribbon's architecture principle during the interview