当前位置:网站首页>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
- regular expression
- Load test practice of pingcode performance test
- VSCode修改缩进不成功,一保存就缩进四个空格
- 数学分析_笔记_第7章:多元函数的微分学
- Master the use of auto analyze in data warehouse
- [unity ugui] scrollrect dynamically scales the grid size and automatically locates the middle grid
- Superscalar processor design yaoyongbin Chapter 7 register rename excerpt
- 第十八届IET交直流輸電國際會議(ACDC2022)於線上成功舉辦
- What grade does Anxin securities belong to? Is it safe to open an account
猜你喜欢
随机推荐
Device interface analysis of the adapter of I2C subsystem (I2C dev.c file analysis)
解读数据安全治理能力评估框架2.0,第四批DSG评估征集中
OPPO小布推出预训练大模型OBERT,晋升KgCLUE榜首
曾经的“彩电大王”,退市前卖猪肉
gatling 之性能测试
Leetcode list summary
curl 命令妙用
【Hot100】31. 下一个排列
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"
What are cache penetration, cache breakdown, and cache avalanche
S5PV210芯片I2C适配器驱动分析(i2c-s3c2410.c)
Internet addiction changes brain structure: language function is affected, making people unable to speak neatly
【测试开发】软件测试——基础篇
你应该懂些CI/CD
Is it safe for Great Wall Securities to open an account? How to open a securities account
新享科技发布小程序UniPro小优 满足客户移动办公场景
About the pit of firewall opening 8848 when Nacos is started
How to choose one plus 10 pro and iPhone 13?
Flask lightweight web framework
To sort out messy header files, I use include what you use








