shell 字符串转数组 数组转字典

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wojiuguowei/article/details/84402890
#!/bin/bash

declare -A dic
test='status=OK key1=value1 key2=value2'
dic=()
arr=($test)
for i in "${arr[@]}"; do
    key=`echo $i|awk -F'=' '{print $1}'`
    value=`echo $i|awk -F'=' '{print $2}'`
    printf "%s\t\n" "$i"
    dic+=([$key]=$value)
done

echo ${dic["key1"]}
echo ${dic[*]}

 

没有更多推荐了,返回首页