sed正则检测开启关闭cdn

sed正则检测开启关闭cdn

#需求,如:
 	   //     //'domain_static' => 1 ? '//img.b-maintain.com/' : '',
以//开头;或以//空格,制表符开头;或以//开头,中间制表或空格,又//;
把这些都替换掉,最终如:
'domain_static' => 1 ? '//img.b-maintain.com/' : '',

非常好的一次正则使用
#!/bin/bash
# Author: royoy
# Date  : 07/2019
# Desc  : open&close cdn for xxxtyt

# Source font file
. /etc/rc.d/init.d/font

conf_php="/data/xxxtyt/config/var.php"
reg="img.b-maintain.com"
cdn_opt="$1"

manage_cdn(){
        [ "x$1" = "xcheck_cdn" ] && {
                if `grep "$reg" $conf_php | grep -E "^\s*'" |grep -q '1'`;then font -d "CDN-当前状态: " -green "开启" -reset -n;else font -d "CDN-当前状态: " -yellow "关闭" -reset -n;fi
        } || {
                [ "x$1" = "xopen_cdn" ] && {
                        sed -i -r '/'$reg'/{s@^[ |/|\t]*/*@\t@;/'$reg'/s/0/1/}' $conf_php && font -d "Open CDN\t" -green "OK" -reset -n
                } || {
                        [ "x$1" = "xclose_cdn" ] && sed -i '/'$reg'/s@^@//&@;/'$reg'/s/1/0/' $conf_php && font -d "Close CDN\t" -green "OK" -reset -n
                }
        }
}

# Interactive mode
while [[ $# -eq 0 ]]
do
        stty erase ^H
        font "Please input an option for CDN of xxxtyt: (c|check) ( o|open ) ( d|close ) ( q|e|quit|exit )" -n
        read OPTARG
        case $OPTARG in
                check|c)
                        manage_cdn "check_cdn"
                                                ;;
                open|o)
                        manage_cdn "open_cdn"
                        ;;
                close|d)
                        manage_cdn "close_cdn"
                        ;;
                exit|quit|q|e)
                        exit
        esac
done

# Auto mode
[[ "check_cdn open_cdn close_cdn" =~ "$cdn_opt" ]] && manage_cdn "$cdn_opt"