Naive approach
To get the unique elements of arr
and assuming that no element contains newlines:
$ printf "%s\n" "${arr[@]}" | sort -u
aa
ab
bb
cc
Better approach
To get a NUL-separated list that works even if there were newlines:
$ printf "%s\0" "${arr[@]}" | sort -uz
aaabbbcc
(This, of course, looks ugly on a terminal because it doesn't display NULs.)
Putting it all together
To capture the result in newArr
:
$ newArr=(); while IFS= read -r -d '' x; do newArr+=("$x"); done < <(printf "%s\0" "${arr[@]}" | sort -uz)
After running the above, we can use declare
to verify that newArr
is the array that we want:
$ declare -p newArr
declare -a newArr=([0]="aa" [1]="ab" [2]="bb" [3]="cc")
For those who prefer their code spread over multiple lines, the above can be rewritten as:
newArr=()
while IFS= read -r -d '' x
do
newArr+=("$x")
done < <(printf "%s\0" "${arr[@]}" | sort -uz)
Additional comment
Don't use all caps for your variable names. The system and the shell use all caps for their names and you don't want to accidentally overwrite one of them.