Loop through array of arrays of string with spaces

前端 未结 2 487
野的像风
野的像风 2021-02-08 14:50

I\'m trying to loop through an array that contains other arrays and these arrays consist of strings with spaces. The problem is that I can\'t seem to preserve the spacing in the

2条回答
  •  孤城傲影
    2021-02-08 15:10

    Replace eval with indirect parameter expansion, and you'll get what I think you want (although it doesn't match your current given output:

    for high_item in "${high[@]}"
    do
        arrayz="$high_item[@]"
        # arrayz is just a string like "low1[@]"
        for item in "${!arrayz}"
        do
            echo $item
        done
    done
    

    Note the need to quote the array expansion in the inner loop to preserve the whitespace in elements of low1.

提交回复
热议问题