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

边栏推荐
- At the end of the year, I'll teach you how to get high performance!
- WGAN、WGAN-GP、BigGAN
- Introduction to regular expressions of shell, general matching, special characters: ^, $,., * Character range (brackets): [], special characters: \, matching mobile phone number
- 习题 --- 快排、归并、浮点数二分
- I grabbed a ticket and thought I found the system bug of 12306
- Why do microservices have to have API gateways?
- PCL各模块概述(1.6)
- Food safety | the kitchen board environment is very important. Do you know these use details?
- 活体检测综述
- Go Basics - arrays and slices
猜你喜欢

I grabbed a ticket and thought I found the system bug of 12306
![[scm] source code management - lock of perforce branch](/img/c6/daead474a64a9a3c86dd140c097be0.jpg)
[scm] source code management - lock of perforce branch
![[SCM]源码管理 - perforce 分支的锁定](/img/c6/daead474a64a9a3c86dd140c097be0.jpg)
[SCM]源码管理 - perforce 分支的锁定

WGAN、WGAN-GP、BigGAN

刷题《剑指Offer》day04

Live countdown 3 days sofachannel 29 P2P based file and image acceleration system Dragonfly

Food safety | are you still eating fermented rice noodles? Be careful these foods are poisonous!

Write yourself a year-end summary. Happy New Year!

Understand chisel language. 24. Chisel sequential circuit (IV) -- detailed explanation of chisel memory

食品安全 | 还在吃酵米面吗?当心这些食物有毒!
随机推荐
WGAN、WGAN-GP、BigGAN
Anchor free detector: centernet
What age are you still using date
Food safety | are you still eating fermented rice noodles? Be careful these foods are poisonous!
原生input标签的文件上传
3D face reconstruction and dense alignment with position map progression network
pillow的原因ImportError: cannot import name ‘PILLOW_VERSION‘ from ‘PIL‘,如何安装pillow<7.0.0
历时一年,论文终于被国际顶会接收了
PCL的ICP配准示例
Towards the peak of life
Leetcode.565. array nesting____ Violent dfs- > pruning dfs- > in situ modification
Gbase 8A MPP cluster capacity expansion practice
Stylegan paper notes + modify code to try 3D point cloud generation
Shell的read 读取控制台输入、read的使用
July training (day 24) - segment tree
去 OPPO 面试,被问麻了
视觉SLAM十四讲笔记(一):第一讲+第二讲
Leetcode.1260. 2D grid migration____ In situ violence / dimensionality reduction + direct positioning of circular array
In depth analysis, sub database and sub table are the most powerful auxiliary sharding sphere
Review of in vivo detection