当前位置:网站首页>shell脚本的替换功能实现
shell脚本的替换功能实现
2022-07-04 15:42:00 【Wu_Candy】
Shell 是一个用 C 语言编写的程序,它是用户使用 Linux 的桥梁。Shell 既是一种命令语言,又是一种程序设计语言。 Shell 是指一种应用程序,这个应用程序提供了一个界面,用户通过这个界面访问操作系统内核的服务。
Shell 脚本(shell script),是一种为 shell 编写的脚本程序。 运行 Shell 脚本有两种方法: 1、作为可执行程序 将代码保存为 test.sh,并 cd 到相应目录: chmod +x ./test.sh #使脚本具有执行权限 ./test.sh #执行脚本
2、作为解释器参数 这种运行方式是,直接运行解释器,其参数就是 shell 脚本的文件名,如: /bin/bash test.sh
目的:将jvm启动时的设置为2048M的内存分配调整为1024M
#!/bin/bash #表示指定了shell脚本解释器的路径
baseDir="/home/q/www" #定义了一个目录变量
function replace() { #定义了一个方法,在下面的for 循环中调用
filename=$1 #接收第一个参数
from=$2 #接收第二个参数
to=$3 #接收第三个参数
echo 'Processing '$filename #输出正在处理的文件名
sudo sed -i "s/$from/$to/g" $filename #真正替换的命令sed
c=`grep "$from" $filename | wc -l` #统计替换后的次数
if [[ $c != 0 ]]; then #如果统计后的次数不为0就表示替换失败
echo "replace $filename failed!" #输出替换失败的提示语
exit 1 #退出
fi #if判断的结束
echo "Replace $filename success!" #输出替换成功的提示语
}
for this in `find $baseDir -type f -name startenv.sh`; #找到指定目录下的文件名为startenv.sh 的文件,并执行for 循环
do #开始执行
# 替换jdk配置
echo $this #输出找到的文件名及全路径
replace $this "2048" "1024" #调用上面定义的方法去执行替换操作
done #结束执行
边栏推荐
- 解读数据安全治理能力评估框架2.0,第四批DSG评估征集中
- [acwing] 58 weeks 4490 dyeing
- 智慧物流園區供應鏈管理系統解决方案:數智化供應鏈賦能物流運輸行業供應鏈新模式
- Learn more about the basic situation of 2022pmp examination
- 【HCIA持续更新】广域网技术
- Go language loop statement (under Lesson 10)
- Implementation of super large-scale warehouse clusters in large commercial banks
- CANN算子:利用迭代器高效实现Tensor数据切割分块处理
- 码农版隐秘的角落:作为开发者最讨厌的5件
- 【模板】【luogu P4630】Duathlon 铁人两项(圆方树)
猜你喜欢
[unity ugui] scrollrect dynamically scales the grid size and automatically locates the middle grid
Yanwen logistics plans to be listed on Shenzhen Stock Exchange: it is mainly engaged in international express business, and its gross profit margin is far lower than the industry level
How to choose one plus 10 pro and iPhone 13?
leetcode:421. The maximum XOR value of two numbers in the array
Zhijieyun - meta universe comprehensive solution service provider
7 RSA密码体制
C# 服务器日志模块
开发者,MySQL专栏完更,助你轻松从安装到入门进阶
【HCIA持续更新】广域网技术
Difference between redis' memory obsolescence strategy and expiration deletion strategy
随机推荐
Is it safe for Bank of China Securities to open an account online?
【HCIA持续更新】WLAN工作流程概述
Understand ThreadLocal in one picture
【HCIA持续更新】广域网技术
一文掌握数仓中auto analyze的使用
容器环境minor gc异常频繁分析
超大规模数仓集群在大型商业银行的落地实践
PingCode 性能测试之负载测试实践
[unity ugui] scrollrect dynamically scales the grid size and automatically locates the middle grid
Load test practice of pingcode performance test
Capvision Rongying's prospectus in Hong Kong was "invalid": it was strictly questioned by the CSRC and required supplementary disclosure
VB cannot access database stocks
【Unity UGUI】ScrollRect 动态缩放格子大小,自动定位到中间的格子
tx.origin安全问题总结
To sort out messy header files, I use include what you use
Unity interview questions (continuously updated)
动态规划股票问题对比
第十八届IET交直流輸電國際會議(ACDC2022)於線上成功舉辦
wuzhicms代码审计
图像检索(image retrieval)