当前位置:网站首页>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会将最后一句返回
边栏推荐
- One dimensional array exercise
- 全局components组件注册
- 365 day challenge leetcode 1000 questions - day 037 elements and the maximum side length of squares less than or equal to the threshold + the number of subsequences that meet the conditions
- Camunda 1、Camunda工作流-介绍
- C language file operation
- 【C语言系列】— 一道递归小题目
- Container security open source detection tool - veinmind (mirror backdoor, malicious samples, sensitive information, weak password, etc.)
- 如视技术副总裁杨永林:当传统产业遇到“数字空间”
- 【C语言系列】— 不创造第三个变量,实现两个数的交换
- 365 day challenge leetcode 1000 questions - day 039 full binary tree inserter + find peak II + snapshot array
猜你喜欢

Best practices of JD cloud Distributed Link Tracking in financial scenarios

力扣994:腐烂的橘子(BFS)

Helm chart for Kubernetes

省市区三级联动(简单又完美)

哈夫曼树以及哈夫曼编码在文件压缩上的应用

阿里云联合鼎捷软件发布云上数字工厂解决方案,实现云MES系统本地化部署

365 day challenge leetcode1000 question - distance between bus stops on day 038 + time-based key value storage + array closest to the target value after transforming the array and + maximum value at t

实现简单的数据库查询(不完整)

C语言 一维数组

B - 识别浮点常量问题
随机推荐
ClickHouse学习(五)集群操作
哈夫曼树以及哈夫曼编码在文件压缩上的应用
NVIDIA Zhou Xijian: the last mile from design to digital marketing
ANSI C type qualifier
Storage category
C language n queen problem
【C语言系列】—深度解剖数据在内存中的存储(二)-浮点型
Bubble sort c language
·来一篇编程之路的自我介绍吧·
Basic principle of recursion
阿里云联合鼎捷软件发布云上数字工厂解决方案,实现云MES系统本地化部署
题解:在一个排序数组中查找元素第一个和最后一个的位置 (个人笔记)
Introduction to array learning simple question sum of two numbers
递归的基本原理
Redirection and files
Side effects and sequence points
Day 5
数据库操作 Day 6
水一篇图的拓扑排序
Application of Huffman tree and Huffman coding in file compression