Create associative array in bash 3

前端 未结 5 1920
独厮守ぢ
独厮守ぢ 2020-12-01 06:31

After thoroughly searching for a way to create an associative array in bash, I found that declare -A array will do the trick. But the problem is, it is only for

5条回答
  •  被撕碎了的回忆
    2020-12-01 07:08

    You can write the key-value pairs to a file and then grep by key. If you use a pattern like

    key=value
    

    then you can egrep for ^key= which makes this pretty safe.

    To "overwrite" a value, just append the new value at the end of the file and use tail -1 to get just the last result of egrep

    Alternatively, you can put this information into a normal array using key=value as value for the array and then iterator over the array to find the value.

提交回复
热议问题