The best solution probably is, as already been pointed out, to iterate through the array and copy it step by step. Steps To Reproduce Install the minimal install, log in, create an associative array with one of the special characters: The live ISO reports the exact same version of bash--4.2.46(2)-release (x86_64-redhat-linux-gnu)--but parses the keys correctly. In some programming languages, arrays has to be declared, so that memory will be allocated for the arrays. Deleting an element from the array To delete an element from the array we need to know it's index or its key in the case of an associative array, and use the unset command. THE_LIST=( "'item1' 'data1 data2'" "'item1' 'data2 data3'" "'item2' 'data4'" ) Based on the above, I want to create an associative array that would assign itemN as key and dataN as value.. My code iterates over the list, and assigns key => value like this (the additional function is shortened, as it performs some additional jobs on the list): Any variable may be used as an indexed array; the declare builtin will explicitly declare an array. You can use any string or integer as a subscript to access array elements.The subscripts and values of associative arrays are called key value pairs. This is not a complicated subject, but you have to be careful when writing your code because you will have extra brackets, braces, … 6.7 Arrays. In associative array, the key-value pairs are associated with => symbol. Awk supports only associative array. An associative array lets you create lists of key and value pairs, instead of just numbered values. Bash, however, includes the ability to create associative arrays, and it treats these arrays the same as any other array. It sorts the associative array named ARRAY and stores the results in an indexed array named KEYS. They are one-to-one correspondence. Copying associative arrays is not directly possible in bash. Bash provides one-dimensional indexed and associative array variables. A detailed explanation of bash’s associative array Bash supports associative arrays. Keys are unique and values can not be unique. There is another solution which I used to pass variables to functions. They work quite similar as in python (and other languages, of course with fewer features :)). You can assign values to arbitrary keys: $ In associative arrays, you can store a piece of data, or value with an identifying ‘key’. It then uses this sorted array to loop through the associative array ARRAY. We will go over a few examples. Today, I’m going to give you some examples on how to work with associative arrays in bash / ksh. Program: Program to loop through associative array and print keys. For example, the associative array userinfo has multiple values, each identified with a key: Dictionary / associative arrays / hash map are very useful data structures and they can be created in bash. Also, array indexes are typically integer, like array[1],array[2] etc., Awk Associative Array. dictionaries were added in bash version 4.0 and above. I've got an array that contains duplicate items, e.g. Using a C-style for loop, it loops through the associative array named ARRAY using the associative array's keys and outputs both the key and values for each item. Let's see an example: There is no maximum limit on the size of an array, nor any requirement that members be indexed or assigned contiguously. Associative arrays are like traditional arrays except they uses strings as their indexes rather than numbers. To use associative arrays, you need […] Introduction to bash arrays and bash array operations. One of the advantages of zsh over bash 3 is the support of “associative arrays,” a data structure known as hash tables or dictionaries in other languages. Method 1: In this method, traverse the entire associative array using foreach loop and display the key elements. To check the version of bash run following: You could use the same technique for copying associative arrays: