当前位置:网站首页>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
边栏推荐
猜你喜欢

.NET6之MiniAPI(十四):跨域CORS(上)

3D Semantic Segmentation - 2DPASS

图论-虚拟节点分层建图

redis持久化方式

First domestic open source framework 】 【 general cloud computing framework, any program can be made into cloud computing.

complete binary tree problem
![[Paper Reading] TRO 2021: Fail-Safe Motion Planning for Online Verification of Autonomous Vehicles Using Conve](/img/17/342676e20fc04ce9083c5ed443bc1d.png)
[Paper Reading] TRO 2021: Fail-Safe Motion Planning for Online Verification of Autonomous Vehicles Using Conve

Lift, Splat, Shoot: Encoding Images from Arbitrary Camera Rigs by Implicitly Unprojecting to 3D 论文笔记

射频芯片ATE测试从入门到放弃之参数测试

Fluorescein-PEG-CLS,胆固醇-聚乙二醇-荧光素科研试剂
随机推荐
《数字经济全景白皮书》金融数字用户篇 重磅发布!
Kotlin - extension functions and operator overloading
Binary search tree to solve the fallen leaves problem
牛客2022 暑期多校3 H Hacker(SAM + 线段树查询区间内部最大子段和)
"Digital Economy Panorama White Paper" Financial Digital User Chapter released!
MiniAPI of .NET6 (14): Cross-domain CORS (Part 1)
Quickly build a website with static files
数据分析知识点搜集(纯粹的搜集)
Republish the lab report
jav一键生成数据库文档
AOSP CameraLatencyHistogram的原理与使用
Unity2021 releases WebGL fog effect disappearing problem
禾匠编译错误记录
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
Cloud platform construction solutions
【论文阅读】TRO 2021: Fail-Safe Motion Planning for Online Verification of Autonomous Vehicles Using Conve
Software testing is seriously involution, how to improve your competitiveness?
Code Casual Recording Notes_Dynamic Programming_416 Segmentation and Subsetting
射频芯片(RFIC)的协议之5G及其调制
【LeetCode】最长公共子序列(动态规划)