当前位置:网站首页>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
边栏推荐
猜你喜欢
7 RSA Cryptosystem
Interpretation of data security governance capability evaluation framework 2.0, the fourth batch of DSG evaluation collection
Ble HCI flow control mechanism
【HCIA持续更新】WLAN工作流程概述
如何进行MDM的产品测试
Electronic pet dog - what is the internal structure?
Solve the El input input box For number number input problem, this method can also be used to replace the problem of removing the arrow after type= "number"
【HCIA持续更新】WLAN概述与基本概念
MVC mode and three-tier architecture
Talk about seven ways to realize asynchronous programming
随机推荐
About the pit of firewall opening 8848 when Nacos is started
NFT liquidity market security issues occur frequently - Analysis of the black incident of NFT trading platform quixotic
简单易用的地图可视化
使用3DMAX制作一枚手雷
“在越南,钱就像躺在街上”
What grade does Anxin securities belong to? Is it safe to open an account
78岁华科教授冲击IPO,丰年资本有望斩获数十倍回报
雨量预警广播自动化数据平台BWII 型广播预警监测仪
Blood spitting finishing nanny level series tutorial - play Fiddler bag grabbing tutorial (2) - first meet fiddler, let you have a rational understanding
正则表达式
Offline and open source version of notation -- comprehensive evaluation of note taking software anytype
补能的争议路线:快充会走向大一统吗?
【Proteus仿真】基于VSM 串口printf调试输出示例
什么是低代码开发?
中断的顶半部和底半部介绍以及实现方式(tasklet 和 工作队列)
Is it safe for Great Wall Securities to open an account? How to open a securities account
五千字讲清楚团队自组织建设 | Liga 妙谈
Superscalar processor design yaoyongbin Chapter 6 instruction decoding excerpt
居家打工年入800多万,一共五份全职工作,他还有时间打游戏
内核中时间相关的知识介绍