当前位置:网站首页>Shell 用法梳理总结
Shell 用法梳理总结
2022-08-03 23:21:00 【fangye945a】
在开发过程中,时不时会需要写一些shell脚本方便开发,但是shell由于不常用,很多用法每次用过后就忘了,每次用每次都要查一下用法。于是想到在此做个梳理总结,方便下次用到。后面开发过程中如果有什么新的用法,再补充到这备忘。
shell脚本文件头
#!/bin/sh
字符串处理
截取字符串方法如下图所示:
sed命令
为"/"添加转义符:
TEST_STR=`echo $TEST_STR | sed 's#\/#\\\/#g'`
grep命令
- grep -v 搜索除指定内容外的内容
- grep -E 搜索支持转义
xargs命令
通过管道传递参数,通常配合其它命令用来删除文件,例如:
删除当前目录下所有.c文件
find ./ -name "*.c" | xargs rm -rf
echo命令
- echo -n 不换行输出
- echo -e 支持转义输出
sed命令
循环语句
条件判断
- 判断文件是否存在
if [ ! -f $CONFIG_FILEPATH ]
then
echo "The $CONFIG_FILEPATH is not exist."
exit 0
fi
- 判断字符串是否为空
if [ -z $CONFIG_STR ]
then
echo "The CONFIG_STR is NULL!"
exit 0
fi
- 条件语句
if [ $CONFIG_SETTING == "Y" ]
then
echo "CONFIG_SETTING is Y"
else
echo "CONFIG_SETTING is not Y"
fi
边栏推荐
- 栈的压入、弹出序列
- First domestic open source framework 】 【 general cloud computing framework, any program can be made into cloud computing.
- Republish the lab report
- 藏宝计划TreasureProject(TPC)系统模式开发技术原理
- Shell编程之循环语句与函数
- ML之yellowbrick:基于titanic泰坦尼克是否获救二分类预测数据集利用yellowbrick对LoR逻辑回归模型实现可解释性(阈值图)案例
- AOSP CameraLatencyHistogram的原理与使用
- (PC+WAP)织梦模板不锈钢类网站
- rosbridge-WSL2 && carla-win11
- RPA助力商超订单自动化!
猜你喜欢
Deep integration of OPC UA and IEC61499 (1)
响应式织梦模板除尘器类网站
V8中的快慢数组(附源码、图文更易理解)
数据分析知识点搜集(纯粹的搜集)
First domestic open source framework 】 【 general cloud computing framework, any program can be made into cloud computing.
Binary search tree to solve the fallen leaves problem
智能座舱的「交互设计」大战
走迷宫 BFS
牛客2022 暑期多校3 H Hacker(SAM + 线段树查询区间内部最大子段和)
[Paper Reading] TRO 2021: Fail-Safe Motion Planning for Online Verification of Autonomous Vehicles Using Conve
随机推荐
golang写的存储引擎,基于b+树,mmap
.NET6之MiniAPI(十四):跨域CORS(上)
complete binary tree problem
ts用法大全
Another MySQL masterpiece published by Glacier (send the book at the end of the article)!!
Flutter教程之为什么 Flutter 是创业的最佳选择?
单例模式使用饿汉式和懒汉式创建一定安全?很多人不知
《数字经济全景白皮书》金融数字用户篇 重磅发布!
Redis persistence method
utils timer
SRE运维解密-什么是SRE:DevOps模型的具体实践!
The sword refers to the offer question 22 - the Kth node from the bottom in the linked list
Cloud platform construction solutions
BMN: Boundary-Matching Network for Temporal Action Proposal Generation阅读笔记
Unity 截取3D图像 与 画中画PIP的实现
Zilliz 2023 秋季校园招聘正式启动!
ML之yellowbrick:基于titanic泰坦尼克是否获救二分类预测数据集利用yellowbrick对LoR逻辑回归模型实现可解释性(阈值图)案例
HCIP BGP实验报告
(PC+WAP)织梦模板螺钉手柄类网站
获国际权威认可 | 云扩科技入选《RPA全球市场格局报告,Q3 2022》