How to create Variable Array names in bash shell scripts?

Short form and crux of question is:

How do I make ArrayName as used below a variable and the arrays will work with variable changed ??

The code below works in a terminal with a fixed array name.

ArrayName[0,1]="False"
echo " ArrayName[0,1] = "${ArrayName[0,1]}" ";

Now, how to make **ArrayName** a variable ?

Your question is not clear. Can you explain it better?

I want to see if it is possible to have

Set

    ArrayName="myarray1"
    $ArrayName[0,1]="False"; as an example

then

echo " myarray[0,1] = “myarray1[0,1]}” "

should show the result.=False

I never could find out how to create variable name arrays.
That is what it is about.
.

Look at it like this.

I am not allowed to create
Array$X [1]=1

and definitely not
$X=5
$XArray[1]=1.

I want to find out why I cannot create arrays with variables as names.

You can’t do that as it goes against shell variable/array naming schema. I believe you can only letters and numbers including _ in bash variable names.

I will probably delete this post as it is about why arrays cannot be assigned in certain ways. The reasons are still a mystery to me and propbably always will be. And none of the books I have addresses the naming conventions of arrays in a consistent manner. So I always get tangled up with array naming as it seldom behave as expected.
So you are left to reverse engineer and test every time you need to use arrays creatively, rather than having a consistent understanding.


Linux sysadmin blog - Linux/Unix Howtos and Tutorials - Linux bash shell scripting wiki