将数组传递给shell

时间:2016-03-16 16:20:17

标签: linux bash shell sh

我在bash中声明了哈希映射,然后尝试在新shell中返回查找值。

因此地图定义如下:

declare -x -A hashmap
hashmap=( ["index1"]="thisisone" ["index2"]="thisistwo")

现在我想发出一个命令的并行实例,其中我找到了我想要处理的文件的路径,根据正在处理的文件在表中查找值,然后将查找值存储在shelled命令中供以后使用:

find . -name '*.bam' | xargs -n 1 -P $threads -iFILES bash -c 'var=$(echo '${hashmap[FILES]}')'

这里似乎存在一些问题,首先关闭FILES变量并未正确传递给查找。我已经尝试将FILES分配给局部变量,并将局部变量作为文字传递,但是我得到了#34;错误的数组下标"错误。

find . -name '*.bam' | xargs -n 1 -P $threads -iFILES bash -c 'var=$(echo FILES); echo '${hashmap["$(echo $var)"]}';'

我试过转储整个地图:

find . -name '*.bam' | xargs -n 1 -P 8 -iFILES bash -c 'v="@"; echo '${hashmap["$v"]}''

它给出了相同的下标错误,但是当我直接传递@字符时,它起作用:

find . -name '*.bam' | xargs -n 1 -P 8 -iFILES bash -c 'echo '${hashmap[@]}''

我是如何获得理想行为的?

提前致谢, 玛蒂

0 个答案:

没有答案
相关问题