当前位置:网站首页>Implementation of replacement function of shell script
Implementation of replacement function of shell script
2022-07-07 07:59:00 【Wu_ Candy】
Shell brief introduction
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 run
Shell Script (shell script), It's for Shell Write the script .
function Shell There are two ways to script :
1、 As an executable
Step1: Save the code as test.sh file
Step2: and cd To test.sh File directory
Step3: chmod +x ./test.sh # Give the script permission to execute
Step4: ./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 , Execute the order as follows :
/bin/bash test.sh
Shell Implementation of script replacement function
The goal is : take jvm The setting at startup is 2048M The memory allocation of is adjusted to 1024M
The specific implementation script code is as follows :
#!/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
above Shell Each line of the script has clear comments , It is recommended that you read .
Welcome to your attention 【 The way of immeasurable testing 】 official account , reply 【 Claim resources 】
Python+Unittest frame API automation 、
Python+Unittest frame API automation 、
Python+Pytest frame API automation 、
Python+Pandas+Pyecharts Big data analysis 、
Python+Selenium frame Web Of UI automation 、
Python+Appium frame APP Of UI automation 、
Python Programming learning resources dry goods 、
Vue Front end component framework development 、
Resources and code Free ~
Below the official account is two-dimensional code. , You can directly scan wechat and pay attention .
remarks : My official account has been officially opened. , betake IT Sharing of Internet technology .
contain : Data analysis 、 big data 、 machine learning 、 Test Development 、API Interface automation 、 Test operation and maintenance 、UI automation 、 Performance testing 、 code detection 、 Programming technology, etc .
WeChat search official account :“ The way of immeasurable testing ”, Or scan the qr code below :

Add the attention , Let's grow together !
边栏推荐
- 【VHDL 并行语句执行】
- Regular e-commerce problems part1
- 2022年茶艺师(中级)考试试题及模拟考试
- Cnopendata American Golden Globe Award winning data
- 【obs】win-capture需要winrt
- Technology cloud report: from robot to Cobot, human-computer integration is creating an era
- Qt学习28 主窗口中的工具栏
- Sign up now | oar hacker marathon phase III, waiting for your challenge
- json 数据展平pd.json_normalize
- Value sequence (subsequence contribution problem)
猜你喜欢

Technology cloud report: from robot to Cobot, human-computer integration is creating an era

Introduction to basic components of wechat applet

2022焊工(初级)判断题及在线模拟考试

Is the test cycle compressed? Teach you 9 ways to deal with it

php导出百万数据

微信小程序基本组件使用介绍

探索干货篇!Apifox 建设思路
![[unity] several ideas about circular motion of objects](/img/84/e70c6696629dbe17ace011553f43ff.png)
[unity] several ideas about circular motion of objects

这5个摸鱼神器太火了!程序员:知道了快删!

Sign up now | oar hacker marathon phase III, waiting for your challenge
随机推荐
【VHDL 并行语句执行】
Ansible
leanote私有云笔记搭建
[UVM foundation] what is transaction
[UTCTF2020]file header
LeetCode 90:子集 II
Button wizard script learning - about tmall grabbing red envelopes
LeetCode 40:组合总和 II
[mathematical notes] radian
Linux server development, redis protocol and asynchronous mode
[Matlab] Simulink 自定义函数中的矩阵乘法工作不正常时可以使用模块库中的矩阵乘法模块代替
leetcode:105. Constructing binary trees from preorder and inorder traversal sequences
Zhilian + AV, AITO asked M7 to do more than ideal one
Sign up now | oar hacker marathon phase III, waiting for your challenge
Problem solving: unable to connect to redis
2022年全国最新消防设施操作员(初级消防设施操作员)模拟题及答案
Operation suggestions for today's spot Silver
Why should we understand the trend of spot gold?
Rust versus go (which is my preferred language?)
Live broadcast platform source code, foldable menu bar