批量修改目录下文件内容信息 (sed)

批量修改文件内容

#! /bin/bash

function read_dir(){
for file in `ls $1` 
do
 if [ -d $1"/"$file ] ;then
	read_dir $1"/"$file
 elif [ "mysqlconfig.json" == ${file} ] ; then 
	pathInfo=(${1//\// })  
	 
	 if [ "conf_dev" == ${pathInfo[-1]} ] ;then  
	 
		 echo $1"/"$file   
		# sed -i "s/\"database\"\: \"oldDBname/\"database\"\: \"newDBname/g"  $1"/"$file 
		# sed -i "s/\"host\"\: \"192.168.234.41\"/\"host\"\: \"mysql-db\"/g"  $1"/"$file 
		# sed -i "s/\"user\"\: \"root\"/\"user\"\: \"root\"/g"  $1"/"$file 
		# sed -i "s/\"password\"\: \"mypwd\"/\"password\"\: \"pwdpwd\"/g"  $1"/"$file 
	 fi
 
 
 
 fi
done
} 
 
# 代替conf_dev的db
read_dir $1

批量复制文件

#! /bin/bash

function cpConf2Prod(){
for file in `ls $1` 
do
 if [ -d $1"/"$file ]  ; then
  
   if [ "conf_dev" == $file ] ; then 
   
	## 创建编译生成的包目录
	if [ ! -d "${1}/conf_prod/" ]; then 
		mkdir -p "${1}/conf_prod/"
		echo "${1}/conf_prod/ created!"
	fi
		
    #confDevDir=$1"/"$file"/*"
	
	## 不能直接  cp -rf  "${1}/${file}/*" "${1}/conf_prod/"
	## 会报 找不到文件
	
    confDevDir="${1}/${file}/*"
	cp -rf  $confDevDir "${1}/conf_prod/"
	echo "cp -rf $1/$file/*  $1/conf_prod"
   else 
	 cpConf2Prod $1"/"$file
   fi 
 
 fi
done
} 
 
# 复制conf_dev 到conf_prod
#cpConf2Prod $1

你可能感兴趣的:(开发规范,shell)