当前位置:网站首页>(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
边栏推荐
- Vue project deployment, cleaning cache
- (六)test命令
- Day12 Association serialization processing
- Replace special characters in URL (%e2%80%8b)
- Unit test (II) -- JUnit
- 小程序嵌入网页向小程序跳转并传参,微信小程序中实现公众号授权获取openId
- 网站被黑,通过百度/搜狗等搜索关键词访问跳转到其他网站怎么办?
- 鼠标右键菜单添加快速打开选项遇见的错误:
- C Programming Language(2nd Edition)--读书笔记--1.5
- STM32F10x--C语言-1
猜你喜欢

网站被黑,通过百度/搜狗等搜索关键词访问跳转到其他网站怎么办?

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

Record a bug that failed to pass the authentication of calling feign interface in the scheduled task

@Configurationproperties annotation usage

elemtnui 表格如何修改某行文字颜色(elemtnui table 修改某行文字颜色)
![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

PCRE bypasses regular
![Buuctf [bjdctf2020]ezphp1 detailed explanation](/img/10/d2593dff2f4a5f0ca41a9f651128df.png)
Buuctf [bjdctf2020]ezphp1 detailed explanation

JSX syntax

ModelArts-图像分类and物体检测
随机推荐
js字符串转对象 js对象转字符串 js字符串与对象互转
Buuctf [bjdctf2020]ezphp1 detailed explanation
Stack injection [strong net cup 2019] random note
elemtnui 表格如何修改某行文字颜色(elemtnui table 修改某行文字颜色)
Oracle database parameter change
Vue project deployment, cleaning cache
Day05-Cookie,Session,Csrf
Common mode attack and shared prime of RSA
Initial flask
鼠标右键菜单添加快速打开选项遇见的错误:
Eye of depth III - (7)] mathematics: application of SVD decomposition
(六)test命令
MoveIt2——4.机器人模型和机器人状态
【ElenmentUI el-date-picker日期选择器,结束时间不得早于开始时间,且只能选择距开始时间指定天数的日期】
服务器如何安装宝塔面板?(宝塔面板安装教程)
Fundamentals of IOT development
JSX 语法
Oracle automatic storage management 18C step-by-step installation -2
P6-day01-general attempt (P4 review)
object-fit:cover;在小程序中不起作用,小程序图片变形了如何处理