当前位置:网站首页>Implementation of shell script replacement function
Implementation of shell script replacement function
2022-07-04 17:50:00 【Wu_ Candy】
Shell It's a use. C A program written in a language , It is used by users Linux The bridge .Shell It's a command language , Another programming language . Shell It's an application , This application provides an interface , Users access the services of the operating system kernel through this interface .
Shell Script (shell script), It's for shell Write the script . function Shell There are two ways to script : 1、 As an executable Save the code as test.sh, and cd Go to the appropriate directory : chmod +x ./test.sh # Give the script permission to execute ./test.sh # Execute the script
2、 As interpreter parameters The way it works is , Run the interpreter directly , The parameter is shell The filename of the script , Such as : /bin/bash test.sh
Purpose : take jvm The setting at startup is 2048M The memory allocation of is adjusted to 1024M
#!/bin/bash # Indicates that the shell The path to the script interpreter
baseDir="/home/q/www" # Defines a directory variable
function replace() { # Defines a method , In the following for Cyclic invocation
filename=$1 # Receive the first parameter
from=$2 # Receive the second parameter
to=$3 # Receive the third parameter
echo 'Processing '$filename # Output the file name being processed
sudo sed -i "s/$from/$to/g" $filename # Real replacement command sed
c=`grep "$from" $filename | wc -l` # Count the number of times after replacement
if [[ $c != 0 ]]; then # If the number of times after statistics is not 0 It means that the replacement fails
echo "replace $filename failed!" # Output the prompt of replacement failure
exit 1 # sign out
fi #if The end of judgment
echo "Replace $filename success!" # Output the prompt of successful replacement
}
for this in `find $baseDir -type f -name startenv.sh`; # Find the file named startenv.sh The file of , And implement for loop
do # Start execution
# Replace jdk To configure
echo $this # Output the found file name and full path
replace $this "2048" "1024" # Call the method defined above to perform the replacement operation
done # End to perform
边栏推荐
- 防火墙基础透明模式部署和双机热备
- Summary of tx.origin security issues
- KS007基于JSP实现人个人博客系统
- 如何进行MDM的产品测试
- Great Wall Securities security does not open a securities account
- [template] [Luogu p4630] duathlon Triathlon (round square tree)
- [HCIA continuous update] overview of WLAN workflow
- 新享科技发布小程序UniPro小优 满足客户移动办公场景
- 上网成瘾改变大脑结构:语言功能受影响,让人话都说不利索
- Win32 API access route encrypted web pages
猜你喜欢

简单易用的地图可视化

五千字讲清楚团队自组织建设 | Liga 妙谈

78岁华科教授冲击IPO,丰年资本有望斩获数十倍回报

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.

CocosCreator事件派發使用

The 18th IET AC / DC transmission International Conference (acdc2022) was successfully held online

Datakit -- the real unified observability agent

Vb无法访问数据库stocks

Ks007 realizes personal blog system based on JSP

Interpretation of data security governance capability evaluation framework 2.0, the fourth batch of DSG evaluation collection
随机推荐
数学分析_笔记_第7章:多元函数的微分学
五千字讲清楚团队自组织建设 | Liga 妙谈
【HCIA持续更新】WLAN工作流程概述
中断的顶半部和底半部介绍以及实现方式(tasklet 和 工作队列)
什么是低代码开发?
大规模服务异常日志检索
Implementation of super large-scale warehouse clusters in large commercial banks
I2C子系统之适配器的设备接口分析(i2c-dev.c文件分析)
What grade does Anxin securities belong to? Is it safe to open an account
[test development] software testing - Basics
Master the use of auto analyze in data warehouse
无心剑中译伊丽莎白·毕肖普《一门技艺》
shell脚本的替换功能实现
【Proteus仿真】基于VSM 串口printf调试输出示例
Performance test of Gatling
简单易用的地图可视化
解读数据安全治理能力评估框架2.0,第四批DSG评估征集中
【Hot100】31. 下一个排列
Make a grenade with 3DMAX
Mathematical analysis_ Notes_ Chapter 7: differential calculus of multivariate functions