Search code examples
bashsolarisopensolaris

Bash - iterate over a union of two (disjoint) arrays


I am writing a bash script (for an Open Solaris 11 machine).

I have declared two arrays in the following way:

rpool_fs=(
  "rpool"
  "rpool/ROOT"
  "rpool/ROOT/solaris"
  "rpool/export"
);

shares_fs=(
  "shares"
  "shares/svn"
);

I am able to iterate over the rpool_fs array in the following way:

for i in "${rpool_fs[@]}"
do
  echo $i
done

I would now need to iterate over the union of the rpool_fs and shares_fs arrays. Note that the arrays are disjoint, e.g. I do in fact only need to iterate over a concatention of them. How do I do that?


Solution

  • Just put one after the other:

    for i in "${rpool_fs[@]}" "${shares_fs[@]}"
    do
      echo $i
    done