Map

  1. #!/usr/bin/env bash
  2. declare -A mymap=(["sunjun"]="a" ["jason"]="b" ["lee"]="c")
  3. #输出所有key值
  4. echo ${!mymap[@]}
  5. #输出所有value值
  6. echo ${mymap[@]}
  7. #查找和删除
  8. findkey=$1
  9. value=$2
  10. # 查找
  11. echo ${mymap[$findkey]}
  12. if [ ! -n "${mymap[$findkey]}" ]
  13. then
  14. echo "not find value"
  15. mymap[$findkey]=$value
  16. else
  17. echo "find value"
  18. unset mymap[$findkey]
  19. fi
  20. echo ${!mymap[@]}
  21. echo ${mymap[@]}

awk

根据jar名称,查询pid,kill进程

  1. ps -ef|grep ${jar_name}-exec | grep -v "grep"| awk '{print $2}' |xargs kill -9

if

Shell if 条件判断

数组

shell 使用数组作为函数参数的方法

  1. #!/usr/bin/env bash
  2. function showArr(){
  3. arr=$1
  4. for i in ${arr[*]}; do
  5. echo $i
  6. done
  7. }
  8. regions=("GZ" "SH" "BJ")
  9. showArr "${regions[*]}"