zoukankan      html  css  js  c++  java
  • shell修改配置文件参数

    #! /usr/bin/sh
    # Author: ELIATEN
    
    help_info="The script is used to update sdk version in the sdkomatic configuration files which locate in relative directory '../sdkomatic/'.
    
    Usage: -a add sdk version, -d delete sdk version
    
    Example: ./updateVersion.sh -a 18.2
    
    Notes: the sdkomatic cfg file should be located in relative directory '../sdkomatic/' of current script and the valid cfg files' name should start with 'sdkomatic', end with '.cfg', without 'REL'."
    
    
    check_files()
    {
    
    if [[ -z $1 ]]
    then
            echo 'Did not find any cfg file matches to "ls ../sdkomatic*.cfg|grep -v REL", exit! Please make sure the cfg files are in relative directory "../sdkomatic/".'
            exit
    fi
    
    }
    
    
    add_version()
    {
    # function used to add version to sdkomatic configuration files
    # 查找文件, 即使找不到也忽略报错
    files=`(ls ../sdkomatic/sdkomatic*.cfg|grep -v REL) 2>/dev/null`
    check_files $files
    
    for file in $files
        do
        # 获得sdk_versions的值
       versions
    =`sed '/sdk_versions" :/!d; s/.*://' $file` # delete the space at begging 去掉字符串首的空格 versions=$(echo $versions|sed 's/^\s//') if [[ $versions =~ $1 ]] then echo "no change to "$file else # add '[' at beginning and delete '],' at last of string 为了后面方便替换在前面添加\,去掉最后的] versions="\"${versions/]*/} # add new version new_versions="$versions, $1"      # 替换 sed -i "s/$versions/$new_versions/g" $file if [[ $? -eq 0 ]] then echo "add new version "$1" to "$file" successful" else echo "add new version "$1" to "$file" filed" fi fi done } delete_version() { # function used to delete version from sdkomaitc configuration files files=`(ls ../sdkomatic/sdkomatic*.cfg|grep -v REL) 2>/dev/null` for file in $files do versions=`sed '/sdk_versions" :/!d; s/.*://' $file` versions=$(echo $versions|sed 's/^\s//') if [[ $versions =~ $1 ]] then
        # 为了后面方便替换在前面添加\,去掉最后的]
         versions="\"${versions/]*/}
    
            # delete the version from version list
            new_versions=$(echo $versions|sed "s/$1",*""\s*"//g")
    
              # delete the legacy comma at last if have
            new_versions=$(echo $new_versions|sed 's/,$//g')
    
            sed -i "s/$versions/$new_versions/g" $file
            if [[ $? -eq 0 ]]
                    then
                            echo "delete version "$1" from "$file" successful"
                    else
                            echo "delete version "$1" from "$file" filed"
                    fi
    
        else
            echo "no change to "$file
    
        fi
        done
    }
    
    
    while getopts "a:d:h" opt; do
      case $opt in
        a)
          echo "receive request to add new version: "$OPTARG
          add_version $OPTARG
          ;;
        d)
          echo "receive request to delete version: "$OPTARG
          delete_version $OPTARG
          ;;
        h)
          echo -e $help_info
          ;;
        ?)
          # echo "Invalid option: $OPTARG"
          echo -e $help_info
          ;;
      esac
    done

     文件内容:

    release_definitions:{"sdk_17_3_sdkomatic" : {
                                     "product" : "EPG_MASTER_25",
                                     "sdk_versions" : [17.3],
                                     "artifactory_branch" : "REL_173",
                                     "build_definitions" : "bd_ssr_17_3",
                                     "test_definitions"  : {
                                        "default" : "td_pduip_17_3",
                                        "drop" : "td_drop_17_3"
                                        }
                                     }
                        }
  • 相关阅读:
    《入门经典》——6.15
    《Linear Algebra and Its Application》-chaper1-行化简法解决线性方程组
    《算法实战策略》-chaper19-队列、栈和双端队列
    《Linear Algebra and Its Applications》-chaper1-向量方程、矩阵方程和线性方程组
    辛普森法则
    《训练指南》——6.15
    《入门经典》——6.21
    《算法问题实战策略》-chaper13-数值分析
    Scheme 中的 pair 和 list 简述
    C. Friends
  • 原文地址:https://www.cnblogs.com/tlmn2008/p/8509957.html
Copyright © 2011-2022 走看看