How can we get the union of two arrays in Bash?
First, combine the arrays:
arr3=("${arr1[@]}" "${arr2[@]}")
Then, apply the solution from this post to deduplicate them:
# Declare an associative arraydeclare -A arr4# Store the values of arr3 in arr4 as keys.for k in "${arr3[@]}"; do arr4["$k"]=1; done# Extract the keys.arr5=("${!arr4[@]}")
This assumes bash 4+.