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