当前位置:网站首页>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 #结束执行
边栏推荐
- 图像检索(image retrieval)
- Learn more about the basic situation of 2022pmp examination
- 容器环境minor gc异常频繁分析
- 新的职业已经出现,怎么能够停滞不前 ,人社部公布建筑新职业
- 什么是低代码开发?
- 手里10万元存款买什么理财产品收益最高?
- Solution du système de gestion de la chaîne d'approvisionnement du parc logistique intelligent
- Offline and open source version of notation -- comprehensive evaluation of note taking software anytype
- The test experience "tortured" by the PMP test is worth your review
- 智捷云——元宇宙综合解决方案服务商
猜你喜欢

Solution du système de gestion de la chaîne d'approvisionnement du parc logistique intelligent

Electronic pet dog - what is the internal structure?

整理混乱的头文件,我用include what you use

DataKit——真正的统一可观测性 Agent

祝贺Artefact首席数据科学家张鹏飞先生荣获 Campaign Asia Tech MVP 2022

Which domestic cloud management platform manufacturer is good in 2022? Why?

【HCIA持续更新】WLAN工作流程概述

Implementation of super large-scale warehouse clusters in large commercial banks

电子宠物小狗-内部结构是什么?

VMware Tools和open-vm-tools的安装与使用:解决虚拟机不全屏和无法传输文件的问题
随机推荐
51 single chip microcomputer temperature alarm based on WiFi control
【Unity UGUI】ScrollRect 动态缩放格子大小,自动定位到中间的格子
How to "use" Perl modules in directories that are not in @inc- How do I 'use' a Perl module in a directory not in @INC?
Leetcode list summary
CocosCreator事件派发使用
被PMP考试“折磨”出来的考试心得,值得你一览
Learn more about the basic situation of 2022pmp examination
leetcode:421. 数组中两个数的最大异或值
R language plot visualization: plot visualization of multiple variable violin plot in R with plot
Zebras are recognized as dogs, and the reason for AI's mistakes is found by Stanford
建筑建材行业经销商协同系统解决方案:赋能企业构建核心竞争力
[Acwing] 58周赛 4489. 最长子序列
PingCode 性能测试之负载测试实践
网页游戏引擎
居家打工年入800多万,一共五份全职工作,他还有时间打游戏
Analysis of abnormal frequency of minor GC in container environment
PyTorch深度学习快速入门教程
完美融入 Win11 风格,微软全新 OneDrive 客户端抢先看
第十八届IET交直流輸電國際會議(ACDC2022)於線上成功舉辦
中信证券网上开户安全吗 开户收费吗