${(u)…}: Deduplicate words

u expands only the first occurrence of each word, i.e. it does not show duplicates in the result.

Examples

Deduplicate words of a string
1
2
3
4
5
6
value="Genius is one percent inspiration and ninety-nine percent perspiration."
IFS=" ."
# deduplicate
echo ${(u)=value}
# deduplicate, upper-case, sort
echo ${(uUo)=value}
Output:
1
2
Genius is one percent inspiration and ninety-nine perspiration 
AND GENIUS INSPIRATION IS NINETY-NINE ONE PERCENT PERSPIRATION
BashSupport Pro is a Zsh IDE with support for ${(u)…}try it now!
© 2020–2024 Joachim Ansorg
Imprint
Privacy Policy
Legal