当前位置:网站首页>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 #结束执行
边栏推荐
- With an annual income of more than 8 million, he has five full-time jobs. He still has time to play games
- Offline and open source version of notation -- comprehensive evaluation of note taking software anytype
- The winning rate against people is 84%, and deepmind AI has reached the level of human experts in army chess for the first time
- Web game engine
- Is it safe for Bank of China Securities to open an account online?
- kaili不能输入中文怎么办???
- 长城证券安全不 证券开户
- C# 更加优质的操作MongoDB数据库
- Go language loop statement (under Lesson 10)
- 动态规划股票问题对比
猜你喜欢
Zhijieyun - meta universe comprehensive solution service provider
Kunming Third Ring Road Closure project will pass through these places. Is there one near your home?
【HCIA持续更新】广域网技术
To sort out messy header files, I use include what you use
Firewall basic transparent mode deployment and dual machine hot standby
Blood spitting finishing nanny level series tutorial - play Fiddler bag grabbing tutorial (2) - first meet fiddler, let you have a rational understanding
NFT liquidity market security issues occur frequently - Analysis of the black incident of NFT trading platform quixotic
Chow Tai Fook fulfills the "centenary commitment" and sincerely serves to promote green environmental protection
Difference between redis' memory obsolescence strategy and expiration deletion strategy
La 18e Conférence internationale de l'IET sur le transport d'électricité en courant alternatif et en courant continu (acdc2022) s'est tenue avec succès en ligne.
随机推荐
网页游戏引擎
R语言plotly可视化:plotly可视化互相重叠的直方图(historgram)、并在直方图的顶部边缘使用geom_rug函数添加边缘轴须图Marginal rug plots
斑马识别成狗,AI犯错的原因被斯坦福找到了丨开源
Great Wall Securities security does not open a securities account
Load test practice of pingcode performance test
Perfectly integrated into win11 style, Microsoft's new onedrive client is the first to see
第十八届IET交直流输电国际会议(ACDC2022)于线上成功举办
How to choose one plus 10 pro and iPhone 13?
The 18th IET AC / DC transmission International Conference (acdc2022) was successfully held online
Summary of tx.origin security issues
CocosCreator事件派发使用
R语言plotly可视化:plotly可视化多分类变量小提琴图(multiple variable violin plot in R with plotly)
To sort out messy header files, I use include what you use
关于nacos启动时防火墙开启8848的坑
昆明三环闭合工程将经过这些地方,有在你家附近的吗?
【测试开发】软件测试——基础篇
Image retrieval
Datakit -- the real unified observability agent
Readis configuration and optimization of NoSQL (final chapter)
Hidden corners of coder Edition: five things that developers hate most