HowTo: Copy an Array in bash

If you want to make a copy of an array as an array in bash, you must use this specific syntax in order to get the elements parsed as individual elements.


export -a "$newArray=(${oldArray[*]})"


The asterisk gives access to each element within the original array, and the parentheses ensure the new array is populated also as an array with multiple elements.


Leave a Reply

Your email address will not be published. Required fields are marked *