当前位置:网站首页>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
边栏推荐
- utlis thread pool
- Recognized by International Authorities | Yunzhuang Technology was selected in "RPA Global Market Pattern Report, Q3 2022"
- rosbridge-WSL2 && carla-win11
- 《数字经济全景白皮书》金融数字用户篇 重磅发布!
- Lift, Splat, Shoot: Encoding Images from Arbitrary Camera Rigs by Implicitly Unprojecting to 3D 论文笔记
- Testng监听器
- 冰河又一MySQL力作出版(文末送书)!!
- 直播预告 | 构建业务智联,快速拥抱财务数字化转型
- 1067 Sort with Swap(0, i)
- 用两个栈模拟队列
猜你喜欢

走迷宫 BFS

获国际权威认可 | 云扩科技入选《RPA全球市场格局报告,Q3 2022》

ML's yellowbrick: A case of interpretability (threshold map) for LoR logistic regression model using yellowbrick based on whether Titanic was rescued or not based on the two-class prediction dataset

图论-虚拟节点分层建图

rosbridge-WSL2 && carla-win11

CAS: 178744-28-0, mPEG-DSPE, DSPE-mPEG, methoxy-polyethylene glycol-phosphatidylethanolamine supply

Analysys Analysis: The transaction scale of China's online retail B2C market in Q2 2022 will reach 2,344.47 billion yuan

Code Casual Recording Notes_Dynamic Programming_416 Segmentation and Subsetting

易观分析:2022年Q2中国网络零售B2C市场交易规模达23444.7亿元

【论文阅读】TRO 2021: Fail-Safe Motion Planning for Online Verification of Autonomous Vehicles Using Conve
随机推荐
Kotlin - extension functions and operator overloading
Deep integration of OPC UA and IEC61499 (1)
Scala basics [regular expressions, framework development principles]
Binary search tree to solve the fallen leaves problem
【论文阅读】TRO 2021: Fail-Safe Motion Planning for Online Verification of Autonomous Vehicles Using Conve
FinClip,助长智能电视更多想象空间
七夕活动浪漫上线,别让网络拖慢和小姐姐的开黑时间
Creo9.0 绘制中心线
Testng listener
使用tf.image.resize() 和tf.image.resize_with_pad()调整图像大小
射频芯片ATE测试从入门到放弃之参数测试
Redis persistence method
rsync 基础用法
Storage engine written by golang, based on b+ tree, mmap
log4j-slf4j-impl cannot be present with log4j-to-slf4j
冰河又一MySQL力作出版(文末送书)!!
ts用法大全
Code Casual Recording Notes_Dynamic Programming_416 Segmentation and Subsetting
响应式织梦模板塑身瑜伽类网站
golang写的存储引擎,基于b+树,mmap