On Tue, Mar 10, 2009 at 03:21:38PM -0400, Chris F.A. Johnson wrote: > while [ $n -lt ${#arra...@]} ] > do > case ${array2[$n]} in > *"$match"*) > array1[${#arra...@]}]=${array2[$n]} > unset array2[n]
Unsetting elements of array2 will create holes in the array, which means ${#arra...@]} will no longer be a useful way to iterate through the whole array. (${#arra...@]} will become too small, as it counts the number of elements, rather than naming the highest index and adding one.) To iterate over a sparse array by index, you need to use ${!arra...@]} (requires bash 3.0 or higher) which returns the list of indices. Try replacing your while loop with: for n in ${!arra...@]}