${(-)…}: Sort numerically
(-) sorts decimal integers numerically and supports a leading minus sign for negative numbers.
By using (n) instead, only positive integers are sorted correctly.
With an additional (O), the sort order is reversed: ${(-O)name}.
Links
Examples
- Sort integers
- Output:
1 2declare data=(100 -1 2 3 -10) echo "Sorting positive and negative integers: " ${(-)data}1Sorting positive and negative integers: -10 -1 2 3 100
BashSupport Pro is a Zsh IDE with support for ${(-)…} – try it now!