当前位置:网站首页>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
边栏推荐
- jav一键生成数据库文档
- End-to-End Lane Marker Detection via Row-wise Classification
- Scala basics [regular expressions, framework development principles]
- Create function report error, prompting DECLARE definition syntax problem
- Creo 9.0创建几何点
- complete binary tree problem
- UVa 1025 - A Spy in the Metro (White Book)
- V8中的快慢数组(附源码、图文更易理解)
- golang写的存储引擎,基于b+树,mmap
- Websocket multi-threaded sending message error TEXT_PARTIAL_WRITING--Use case of spin lock replacing synchronized exclusive lock
猜你喜欢

(PC+WAP)织梦模板不锈钢类网站

The salary of soft testers at each stage, come to Kangkang, how much can you get?

Pytest学习-skip/skipif

图论-虚拟节点分层建图

What is the difference between the generator version and the viewer version?
![[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

【开源框架】国内首个通用云计算框架,任意程序都可做成云计算。

Cloud platform construction solutions

直播系统聊天技术(八):vivo直播系统中IM消息模块的架构实践

软件测试内卷严重,如何提升自己的竞争力呢?
随机推荐
Recognized by International Authorities | Yunzhuang Technology was selected in "RPA Global Market Pattern Report, Q3 2022"
websocket多线程发送消息报错TEXT_PARTIAL_WRITING--自旋锁替换synchronized独占锁的使用案例
静态文件快速建站
AOSP CameraLatencyHistogram的原理与使用
Click the icon in Canvas App to generate PDF and save it to Dataverse
Take an example of a web worker
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
override learning (parent and child)
Why do we need callbacks
剑指offer第22题-链表中倒数第K个节点
"Digital Economy Panorama White Paper" Financial Digital User Chapter released!
Republish the lab report
软件测试内卷严重,如何提升自己的竞争力呢?
Interpretation of ML: A case of global interpretation/local interpretation of EBC model interpretability based on titanic titanic rescued binary prediction data set using interpret
用栈实现队列
1067 Sort with Swap(0, i)
代码随想录笔记_动态规划_416分割等和子集
The sword refers to the offer question 22 - the Kth node from the bottom in the linked list
rsync 基础用法
(PC+WAP)织梦模板螺钉手柄类网站