java要多思考下

          成長^_^

             ::  :: 新隨筆 ::  ::  :: 管理 ::
            33 隨筆 :: 0 文章 :: 19 評論 :: 0 Trackbacks
          取腳本運行參數: $0 $1 $2 ...
          取腳本運行參數個數: $#
          取腳本運行的所有參數:$*
          判斷字符串相等:if [[ "$1" = "-cmd" ]]; then command=$2 fi ([后有空格,]前也有空格)
          變量命名:string1="/usr/local/redis/bin/redis-cli"
          取變量值:$string1
          命令調用:`export abc="abc"`
          字符串命令調用:result=`eval $string`
          將命令調用值賦給數組:results=(`eval $string`)
          取數組長度:${#results[@]}
          取數組值:${results[i]}
          取運行參數數組值:${!i}
          調用外部腳本:. xxxx.sh

          附:redis數據批量操作腳本
          #!/bin/bash
          command="keys '*'"
          action="noaction"
          redis_cli="/usr/local/redis/bin/redis-cli"

          if [[ "$1" = "-cmd" ]]; then
              command=$2
          fi

          if [[  "$3" = "-act"  ]]; then
              action=$4
          fi

          #collect the command result to an array named results
          echo "=====> do command: $command"
          exec_command="$redis_cli $command"
          results=(`eval $exec_command`)

          if [[ ${#results[@]} = 0 ]];then
              exit 1
          fi

          for (( i = 0; i < ${#results[@]}; i++ )); do
              case $action in
                  del)
                      doaction="$redis_cli del ${results[i]}"
                      ;;
                  ttl)
                      doaction="$redis_cli ttl ${results[i]}"
                      ;;
                  expire)
                      doaction="$redis_cli expire ${results[i]} 60"
                      ;;
                  *)
                      doaction="echo \"${results[i]}\""
                      ;;
              esac
              
              actionResult=`eval $doaction`
              echo "=====> do action: $doaction ==> result: $actionResult"
          done

          調用形式:
          ./xxxx.sh
          ./xxxx.sh -cmd 'keys aa*'
          ./xxxx.sh -cmd 'keys aa*' -act del
          ./xxxx.sh -cmd 'keys aa*' -act expire
          ./xxxx.sh -cmd 'keys aa*' -act ttl

           
          posted on 2013-02-22 17:50 java要多思考下 閱讀(1796) 評論(0)  編輯  收藏 所屬分類: 系統運維
          主站蜘蛛池模板: 荔波县| 衡阳县| 江门市| 永仁县| 南木林县| 张家界市| 娱乐| 府谷县| 北票市| 巴彦县| 孝昌县| 资源县| 揭东县| 延边| 安庆市| 新巴尔虎左旗| 淮滨县| 池州市| 上虞市| 清水河县| 汉中市| 封开县| 靖江市| 秀山| 连州市| 和顺县| 德江县| 平顶山市| 额尔古纳市| 古交市| 大冶市| 银川市| 阳东县| 永胜县| 昔阳县| 辽宁省| 连城县| 句容市| 平度市| 阆中市| 盐池县|