首页 > 系统服务 > 详细

shell脚本修改配置文件加上或者去掉注释

时间:2021-03-17 17:17:56      阅读:81      评论:0      收藏:0      [点我收藏+]

脚本内容如下

#/bin/bash
set -e
conf=$1
current_path=$(cd $(dirname $0); pwd)
if [ ! -f "$conf" ]; then
echo "the file $conf is not exesit!,please check it"
exit 101
fi
while read line
do
echo $line
if ( echo ${line} |grep -q "//" );
then
echo $line
newline=$(echo $line|cut -b 3-${#line})
sed -i "s#$line#$newline#g" $conf
else
echo $line
newline="//$line"
echo ${newline}
sed -i "s#$line#$newline#g" $conf

fi

done < $current_path/md.conf

 

并在同一级目录创建一个配置文件md.conf,内容配置为你想改的行数内容

调用方式 sh -x mdConf.sh 指定的配置文件

技术分享图片

 

shell脚本修改配置文件加上或者去掉注释

原文:https://www.cnblogs.com/shiyerui/p/14549552.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!