当前位置:网站首页>Ji Geng 43 / 90
Ji Geng 43 / 90
2022-04-21 15:38:00 【Programming Capriccio】
Random thoughts on programming
Bash conditional
if sentence
if commands; then
commands
[elif commands; then commands...]
[else commands]
fi
if The judging condition of structure , In general use test command , There are three forms .
# Writing a
test expression
# Write two
[ expression ]
# Write three
[[ expression ]]
// The above three forms are equivalent , But the third form also supports regular judgment , The first two don't support .
// Be careful , The second and third way of writing ,[ and ] There must be a space between and the inner expression .
File to judge
[ -a file ]: If file There is , Then for true.
[ -d file ]: If file Exists and is a directory , Then for true.
[ -e file ]: If file There is , Then for true.
[ -w file ]: If file Being and writable ( The current user has writable permissions ), Then for true.
[ -x file ]: If file Exists and is executable ( Effective users have execution / Search rights ), Then for true.
String judgment
[ string ]: If string Not empty ( Longer than 0), Then the judgment is true .
[ -n string ]: If the string string The length of is greater than zero , Then the judgment is true .
[ -z string ]: If the string string The length of is zero , Then the judgment is true
[ string1 = string2 ]: If string1 and string2 identical , Then the judgment is true .
[ string1 == string2 ] Equate to [ string1 = string2 ].
[ string1 != string2 ]: If string1 and string2 inequality , Then the judgment is true .
[ string1 '>' string2 ]: If you follow the dictionary order string1 Arrange in string2 after , Then the judgment is true .
[ string1 '<' string2 ]: If you follow the dictionary order string1 Arrange in string2 Before , Then the judgment is true .
// Be careful ,test Inside the command > and <, Must be enclosed in quotation marks ( Or it's a backslash ). otherwise , They will be shell Interpreted as a redirection operator .
Integer judgment
[ integer1 -eq integer2 ]: If integer1 be equal to integer2, Then for true.
[ integer1 -ne integer2 ]: If integer1 It's not equal to integer2, Then for true.
[ integer1 -le integer2 ]: If integer1 Less than or equal to integer2, Then for true.
[ integer1 -lt integer2 ]: If integer1 Less than integer2, Then for true.
[ integer1 -ge integer2 ]: If integer1 Greater than or equal to integer2, Then for true.
[ integer1 -gt integer2 ]: If integer1 Greater than integer2, Then for true.
Regular judgment
[[ string1 =~ regex ]] //regex It's a regular expression ,=~ It's a regular comparison operator .
Logical operations
AND operation : Symbol &&, You can also use parameters -a.
OR operation : Symbol ||, You can also use parameters -o.
NOT operation : Symbol !.
Arithmetic judgment
((...)) As an arithmetic condition , The judgment of arithmetic operations .
if ((3 > 2)); then
echo "true"
fi
// There is no need to use test command , But directly ((...)) structure . The return value of this structure , Determines the authenticity of the judgment .
// If the arithmetic result is nonzero , It means that the judgment is true . This is the opposite of the return value of the command , Need to be careful .
case structure
case expression in
pattern )
commands ;;
pattern )
commands ;;
...
esac
版权声明
本文为[Programming Capriccio]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211536067951.html
边栏推荐
猜你喜欢
![[unity note] l2unity shader Foundation](/img/c0/6f977e8bfe3e31b1bb3a61bfa02861.png)
[unity note] l2unity shader Foundation

72页互联网智慧园区解决方案

左程云 - 大厂刷题班 - 摆砖块

全国降雨侵蚀力因子R值

LeetCode刷题之652寻找重复的子树

Web.xml文件详解

【时序】Reformer:局部敏感哈希(LSH)实现高效 Transformer 论文笔记

Smart Park Digital financing - Digital enabling operation management platform solution

Solve i.mx6u driver transplantation LED flashing

chapter 7类
随机推荐
AcWing 1812. Square pasture (enumeration)
Digital twin planning scheme of Industrial Park
How to apply for corporate email? How to register email with mobile phone number?
JUC concurrent learning notes
易語言CEF3獲取請求返回的源碼
Installation and uninstallation of MySQL
C语言进阶第43式:函数的意义
MySQL8. 0 correct password change posture
终极套娃 2.0|云原生 PaaS 平台的可观测性实践分享
Ultimate doll 2.0 | observable practice sharing of cloud native PAAS platform
Winter is coming. Let's snow your website
111 page data word transformation solution of Fine Chemical Co., Ltd
[unity note] l2unity shader Foundation
C语言进阶第42式:内存操作经典问题分析二
AcWing 1866. Fence painting (section crossing)
92页集团信息化规划方案企业应用集成解决方案
In the SSM project, the test method has been running in circles without stopping
Universal navigation: a concise and practical comprehensive navigation website
AcWing1800. 不做最后一个(枚举)
What is an email address? Easy to use email registration application