小编use*_*400的帖子

Bash扩展哈希表(字典)

我尝试使用文件中的数据填充哈希表.有了这段代码

      templates="./templates"
      declare -A ARRAY
      ARRAY+=([a]='b')
      ARRAY+=([d]='f')
      cat $templates | while read line 
      do
      a=`(echo $line | cut -d ':' -f 1)`
      b=`(echo $line | cut -d ' ' -f 2)`
      ARRAY+=([a]=b)
      done


      for x in ${!ARRAY[@]}
      do
      echo "$x - ${ARRAY["$x"]}"
      done
Run Code Online (Sandbox Code Playgroud)

它只给我

  a - b
  d - f
Run Code Online (Sandbox Code Playgroud)

模板文件是:

nazwisko: towar
Kowalski: ksiazki
Nowak: programy
Run Code Online (Sandbox Code Playgroud)

bash hash dictionary

2
推荐指数
1
解决办法
3679
查看次数

标签 统计

bash ×1

dictionary ×1

hash ×1