How to get a variable by another one in bash?

后端 未结 2 1318
攒了一身酷
攒了一身酷 2021-01-27 15:14

I have three arrays in bash.

 arr1=(arr2 arr3)
 arr2=(1 2 3 4)
 arr3=(6 7 8 9)
 #How can I get a element of arr2 by arr1? like below:
 ${${arr1[0]}[0} # To get f         


        
相关标签:
2条回答
  • 2021-01-27 15:21

    Using eval:

    eval echo \${${arr1[0]}[0]}
    
    0 讨论(0)
  • 2021-01-27 15:34

    An eval-less answer:

    tmp=arr1[0]
    tmp2=${!tmp}
    echo ${!tmp2[0]}
    
    0 讨论(0)
提交回复
热议问题