sh cssupdate 优化


#!/bin/bash

# 更新css文件内图片的版本
# 如background:url('images/test.jpg'); 更新为 background:url('images/test.jpg?20130330121210');

csstmpl_path="/home/fdipzone/php/csstmpl" # css tmpl path
css_path="/home/fdipzone/php/css"         # css path
replacetags=(".png" ".jpg" ".gif")        # file type
convertnum=0
search_child=$1                           # search child

echo ${search_child:=0} > /dev/null

function create(){
    tmplfile=$1
    dfile=$2

    dfolder=${dfile%/*}

    if [ ! -d "$dfolder" ]; then
        mkdir -p $dfolder
    fi

    cp "$tmplfile" "$dfile" #复制tmpl到目标文件

    for tag in ${replacetags[*]} ; do
        newtag="$tag?$(date +%Y%m%d%H%M%S)"
        sed -i "s/$tag/$newtag/g" "$dfile" #使用sed -i 替换文件内容
    done

    convertnum=$(($convertnum+1))

    tolog "$tmplfile convert to $dfile success"
}

function tolog(){
    echo $1
}

function update(){
    if [ -d "$csstmpl_path" ] && [ -d "$css_path" ]; then
        
        if [ "$search_child" -eq 0 ]; then
            maxdepth=" -maxdepth 1 "
        else
            maxdepth=""
        fi

        for file in $(find $csstmpl_path $maxdepth -name "*.css" -type f) ; do
            dfile=${file/$csstmpl_path/$css_path}
            create $file $dfile
        done

        echo "convert num: $convertnum"

    else
        tolog "$csstmpl_path or $css_path not exists"
    fi
}

update

exit 0

查看PHP版

查看上一版

优质内容筛选与推荐>>
1、第五天-2019-11-28基本配置命令
2、2018-09-19 修改V8和node.js建立中文后端开发工具
3、centos7部署rabbitqmq集群
4、异常处理:Invalid bound statement (not found)错误的可能原因
5、团队项目-选题报告


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号