Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 如何在korn shell中访问关联数组中元素的元素_Arrays_Shell_Ksh - Fatal编程技术网

Arrays 如何在korn shell中访问关联数组中元素的元素

Arrays 如何在korn shell中访问关联数组中元素的元素,arrays,shell,ksh,Arrays,Shell,Ksh,两周前我就开始编写脚本,现在我正在尝试使用KornShell脚本中的关联数组创建一个3D数组。我尝试了我能想到的所有可能的组合,但没有使脚本变得很长,但我无法取得任何进展。我试图处理关联数组中的单个元素,但我无法做到这一点。我真的很感激在这方面的任何帮助 #!/usr/bin/ksh93 typeset -A array_of_array #array_of_array is associative array_of_array=([array_index]="A

两周前我就开始编写脚本,现在我正在尝试使用KornShell脚本中的关联数组创建一个3D数组。我尝试了我能想到的所有可能的组合,但没有使脚本变得很长,但我无法取得任何进展。我试图处理关联数组中的单个元素,但我无法做到这一点。我真的很感激在这方面的任何帮助

#!/usr/bin/ksh93

typeset -A array_of_array              #array_of_array is associative

array_of_array=([array_index]="A B C D E"
           [A]="AA AAA AAAA"
           [B]="BB BBB BBBB"
           [C]="CC CCC CCCC"
           [D]="DD DDD DDDD"
           [E]="EE EEE EEEE"
          )

print_fun(){
        for INDEX in ${array_of_array["array_index"]};
        do
                echo "$INDEX --->"

                echo ${${array_of_array[$INDEX]}[0]} #this is incorrect instrn

                for ITEMS in ${array_of_array[$INDEX]}
                do
                        echo $'\t\t\t'$ITEMS
                done
        done
}
print_fun
我试图得到如下输出:

A  --->  AA
         AAA
         AAAA

B  --->  BB
         BBB
         BBBB

C  --->  CC
         CCC
         CCCC

你没有数组的数组;您有一个字符串数组


我将你的问题重新标记为
ksh
,因为
ksh
bash
有很多不同之处。(此处最相关的是,
bash
不允许嵌套数组)。此脚本未运行,显示错误。我们还可以按照上面显示的方式声明关联数组。请您解释一下“${array\u of_array[$INDEX][@]}”说明您使用的是什么版本的
ksh
?在
ksh
93u+2012-08-01中,这对我来说非常有效<代码>外壳检查似乎不支持
ksh
#!/usr/bin/ksh93

typeset -A array_of_array

# This associates another array with each key in the outer array
array_of_array=(
           [A]=(AA AAA AAAA)
           [B]=(BB BBB BBBB)
           [C]=(CC CCC CCCC)
           [D]=(DD DDD DDDD)
           [E]=(EE EEE EEEE)
          )

print_fun(){
        # Use this syntax for iterating over the keys of the outer array
        for INDEX in "${!array_of_array[@]}";
        do
                echo "$INDEX --->"

                # Use this syntax for accessing the elements
                # of the inner array associate with each key
                for ITEMS in "${array_of_array[$INDEX][@]}"
                do
                        echo $'\t\t\t'$ITEMS
                done
        done
}
print_fun