当前位置:网站首页>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
边栏推荐
- What is low code development?
- 你应该懂些CI/CD
- 【系统分析师之路】第七章 复盘系统设计(结构化开发方法)
- 智捷云——元宇宙综合解决方案服务商
- Set the transparent hidden taskbar and full screen display of the form
- Using win10 scheduling task program to automatically run jar package at fixed time
- 长城证券开户安全吗 证券账户怎么开通
- 【HCIA持续更新】WLAN概述与基本概念
- 公司要上监控,Zabbix 和 Prometheus 怎么选?这么选准没错!
- 解决el-input输入框.number数字输入问题,去掉type=“number“后面箭头问题也可以用这种方法代替
猜你喜欢

Self reflection of a small VC after two years of entrepreneurship

Firewall basic transparent mode deployment and dual machine hot standby

To sort out messy header files, I use include what you use

Zhijieyun - meta universe comprehensive solution service provider

Vb无法访问数据库stocks

离线、开源版的 Notion—— 笔记软件Anytype 综合评测

超大规模数仓集群在大型商业银行的落地实践

Ble HCI flow control mechanism

我写了一份初学者的学习实践教程!

曾经的“彩电大王”,退市前卖猪肉
随机推荐
使用3DMAX制作一枚手雷
Zhijieyun - meta universe comprehensive solution service provider
CANN算子:利用迭代器高效实现Tensor数据切割分块处理
[HCIA continuous update] WLAN overview and basic concepts
7 RSA Cryptosystem
超大规模数仓集群在大型商业银行的落地实践
Interpretation of data security governance capability evaluation framework 2.0, the fourth batch of DSG evaluation collection
VB cannot access database stocks
曾经的“彩电大王”,退市前卖猪肉
你应该懂些CI/CD
《吐血整理》保姆级系列教程-玩转Fiddler抓包教程(2)-初识Fiddler让你理性认识一下
【测试开发】软件测试——基础篇
一文掌握数仓中auto analyze的使用
What is low code development?
国产数据库TiDB初体验:简单易用,快速上手
RecastNavigation 之 Recast
Introduction of time related knowledge in kernel
整理混乱的头文件,我用include what you use
Win32 API access route encrypted web pages
Device interface analysis of the adapter of I2C subsystem (I2C dev.c file analysis)