当前位置:网站首页>(6) Test command
(6) Test command
2022-07-19 01:30:00 【Hungry Taibai Xingjun】
#!/bin/bash
# Used to check whether the condition is true : The number 、 Characters and files
# ( One ) The number
:<<EOF
-eq Equal is true
-ne True if not equal
-gt Greater than is true
-ge True if greater than or equal to
-lt Less than is true
-le True if less than or equal to
EOF
num1=100
num2=200
if test ${
num1} -eq ${
num2}
then
echo Two numbers are equal
else
echo Two numbers are not equal
fi
# (1) In code [] Perform basic arithmetic operations , But it's best to use (())
echo "(num1+num2)*num1=$(((num1+num2)*num1))"
# (2)test You can use [] Instead of ,[] A space is required before and after the inside
if [ ${
num1} -eq ${
num2} ]
then
echo Two numbers are equal xxxx
else
echo Two numbers are not equal xxxx
fi
# ( Two ) String test
:<<EOF
= # Equality is true
!= # Inequality is true
-z # String length is 0 It is true
-n # String length is not 0 It is true
EOF
str1="runoob1"
str2="runoob2"
if test $str1 = $str2
then
echo str1=str2
else
echo str1 It's not equal to str2
fi
# String length
if test -z $str2
then
echo str2 is empty
else
echo str2 is not empty
fi
# ( 3、 ... and ) File test
:<<EOF
-e file name True if the file exists
-r file name True if the file exists and is readable
-w file name True if the file exists and is writable
-x file name True if the file exists and is executable
-s file name True if the file exists and has at least one character
-d file name True if the file exists and is a directory
-f file name True if the file exists and is a normal file
-c file name True if the file exists and is a special character file
-b file name True if the file exists and is a block special file
EOF
if test -e ./myfile
then
echo myfile There is
else
echo myfile non-existent
fi
# (3) If then If you start a new line then There is no need to add ; Otherwise, it needs to be in then Before to add ;
if [ -d "/data/" ];then
echo "data Folder exists "
else
echo "data Folder does not exist "
fi
# (4)"/data/" Double quotation marks can be removed .
# ( Four ) And or not -a -o !
# Shell It also provides ( -a )、 or ( -o )、 Not ( ! ) Three logical operators are used to connect test conditions
# Its priority is : ! The highest , -a second , -o The minimum
if [ -e ./notFile -o -e ./myfiel ]; then
echo " At least one file exists "
else
echo " It doesn't exist "
fi
边栏推荐
猜你喜欢
![The eye of Depth III - - (3)] Mathematics: Matrix eigenvalue and eigenvector 1](/img/81/7ad44da70eaf1d92b126c567766577.png)
The eye of Depth III - - (3)] Mathematics: Matrix eigenvalue and eigenvector 1

使用bat自动执行cmd命令(多个命令或单个命令)

js替换字符串某个字符,js修改字符串中指定字符

everything搜索不到startup_lpc11x.s文件

Maker-HarmonyOS应用开发培训笔记01

Single page application spa and multi page application MPa

gtest与gmock的安装与使用

Oracle automatic storage management 18C step-by-step installation -2

Collection and summary of penetration test information

object-fit:cover;在小程序中不起作用,小程序图片变形了如何处理
随机推荐
The C Programing Language-2nd--笔记--4.11.3
Oracle database parameter change
Common mode attack and shared prime of RSA
Unit test (II) -- JUnit
Vue项目部署,清理缓存
MoveIt2——4.机器人模型和机器人状态
Summary of XML external entity injection (xxE target recurrence)
电商后台管理登录
gtest与gmock的安装与使用
jsx 编译
深度之眼三——(7)】数学:svd分解的应用
两表连接进行增删改查
The C Programming Language (2nd)--笔记--1.6
Day13 mixed view base class
Pytoch simply uses the Minist dataset
深度之眼三——(4,5)】数学:矩阵特征值与特征向量2
深度之眼三——(6)】数学:矩阵对角化及二次型1
Day06 ORM field and operation
uni-app微信公众号(4)——地址管理页面
Vue project deployment, cleaning cache