Skip to main content
added 351 characters in body
Source Link
choroba
  • 49.4k
  • 7
  • 92
  • 118

To expand array indirection, the string [@] must be part of the variable. It works for the values:

for thelist in "${master_list[@]}" ; do
    reallist=$thelist[@]
    for key in "${!reallist}" ; do
        echo "the key is: $key"
    done
done

For the keys, I don't see a way without eval.

for thelist in "${master_list[@]}" ; do
    eval keys=('"${!'$thelist'[@]}"')
    for key in "${keys[@]}" ; do
        echo "the key is: $key"
    done
done

As far as you're sure the master_list contains only variable names, it should be safe.

To expand array indirection, the string [@] must be part of the variable:

for thelist in "${master_list[@]}" ; do
    reallist=$thelist[@]
    for key in "${!reallist}" ; do
        echo "the key is: $key"
    done
done

To expand array indirection, the string [@] must be part of the variable. It works for the values:

for thelist in "${master_list[@]}" ; do
    reallist=$thelist[@]
    for key in "${!reallist}" ; do
        echo "the key is: $key"
    done
done

For the keys, I don't see a way without eval.

for thelist in "${master_list[@]}" ; do
    eval keys=('"${!'$thelist'[@]}"')
    for key in "${keys[@]}" ; do
        echo "the key is: $key"
    done
done

As far as you're sure the master_list contains only variable names, it should be safe.

Source Link
choroba
  • 49.4k
  • 7
  • 92
  • 118

To expand array indirection, the string [@] must be part of the variable:

for thelist in "${master_list[@]}" ; do
    reallist=$thelist[@]
    for key in "${!reallist}" ; do
        echo "the key is: $key"
    done
done