当前位置:网站首页>shell基本操作(下)
shell基本操作(下)
2022-07-29 05:09:00 【阳光里哭泣的狗】
运算符
算术运算符
- expr + , - , *, /, % 加,减,乘,除,取余

复合运算,注意``不是单引号
- “ ( ( 运 算 式 ) ) ” 或 “ ((运算式))”或“ ((运算式))”或“[运算式]”

字符串运算符
- = 检测两个字符串是否相等,相对返回true
- != 检测两个字符串是否不相等,不相等返回true
- -z 检测字符串长度是否为0,为0返回true
- -n 检测字符串长度是否不为0,不为0返回true
- $ 检测字符串是否为空,不为空返回true
在流程控制会测试
流程控制
if else 判断
语法:
if [ 条件判断式 ]
then
命令
fi
===============================
if [ 条件判断式 ]
then
命令
else
命令
fi
==============================
if [ 条件判断式 ]
then
命令
elif [ 条件判断式 ]
then
命令
else
命令
fi
注意空格,在if后和[]中都要加上空格
也可以将其写成一句就在每句后加上;如if [ a=b ];then echoxxxxxxx;xxx;xxx;
case 语句
每个 case 分支用右圆括号开始,用两个分号 ;; 表示 break,结束用esac表示
case $变量名 in
"值1")
如果变量的值等于值1,则执行程序1
;;
"值2")
如果变量的值等于值2,则执行程序2
;;
…省略其他分支…
*)
如果变量的值都不是以上的值,则执行此程序
;;
esac


for 循环
和其他语言中的for循环差不多
for 变量 in item1 item2 ... itemN
do
命令
.....
done
==========================
for ((表达式))
do
命令
.....
done

while循环
while [ 条件判断式 ]
do
命令
done
====================
while ((表达式))
do
命令
done

函数
函数名(){
函数体
[return]
}
不加return会将最后一句返回
边栏推荐
猜你喜欢

Occt learning 002 - environment construction

AiTalk创始人梁宇淇:镜像连接虚拟与现实的纽带

重定向和文件

Day 1

Pyqt5: Chapter 1, Section 1: creating a user interface using QT components - Introduction

PyQt5:第一章第1节:使用Qt组件创建一个用户界面-介绍

In depth analysis of common cross end technology stacks of app

Preemptive appointment | Alibaba cloud shadowless cloud application online conference appointment opens

JD cloud and Forrester consulting released a hybrid cloud report that cloud Nativity has become a new engine driving industrial development

Complete ecological map of R & D Efficiency & selection of Devops tools
随机推荐
JD cloud and Forrester consulting released a hybrid cloud report that cloud Nativity has become a new engine driving industrial development
vim编辑器使用
串口通讯部分详解
Best practices for elastic computing in the game industry
时间复杂度和空间复杂度
Container security open source detection tool - veinmind (mirror backdoor, malicious samples, sensitive information, weak password, etc.)
B - identify floating point constant problems
阿里云架构师细说游戏行业九大趋势
微信小程序视频上传组件直接上传至阿里云OSS
牛客网编程题—【WY22 Fibonacci数列】和【替换空格】详解
【C语言系列】—深度解剖数据在内存中的存储(二)-浮点型
【剑指offer】— 详解库函数atoi以及模拟实现atoi函数
一维数组练习
Differences between texture2d and texture2dproj under webgl1.0
200 多家 ISV 入驻!阿里云计算巢发布一周年
Day 2
分配内存:malloc()和free()
【C语言系列】—深度解剖数据在内存中的存储(一) 暑假开篇
QML custom tabbar
整数溢出和打印