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

边栏推荐
猜你喜欢

Qt Creator .pro文件根据kit添加对应库

Beihui information is 12 years old | happy birthday

反常积分的审敛

Google play app store may delete the overview of APP permissions and use a new combination of data security information

云解决方案,为什么选择 AMD EPYC?

0722~ thread pool extension

Outlook tutorial, how to switch calendar views and create meetings in outlook?

Problem solving: script file 'scripts\pip script py‘ is not present.

When using fastjson to parse and assign JSON data, the order of JSON fields is inconsistent
![[jzof] 11 minimum number of rotation array](/img/a3/6c3672a2a7b4f436874664034a4964.png)
[jzof] 11 minimum number of rotation array
随机推荐
ES6——周考题
射击游戏 第 1-2 课:使用精灵
PHP connecting to SQL Server
PHP获取当前时间戳三位毫秒 - 毫秒时间戳
第十天笔记
【可視化調度軟件】上海道寧為SMB組織帶來NETRONIC下載、試用、教程
When using fastjson to parse and assign JSON data, the order of JSON fields is inconsistent
C#做一个简单浏览器
基于BIM+3DGIS的智慧城市基础设施管理
-XX:+UseCGroupMemoryLimitForHeap 无法创建虚拟机问题
第二章关系数据库课后习题
php连接sql server
Introduction to radar part vii 2 imaging method
Uncaught (in promise) Neo4jError: WebSocket connection failure. Due to security constraints in your
Hardware system architecture of 4D millimeter wave radar
Beifu PLC and C transmit bool array variables through ads communication
第九天笔记
[daily training] 814. Binary tree pruning
Successful joint commissioning of Vientiane Aoke and CoDeSys Technology
太空射击 Part 1: 玩家精灵和控制