${(-)…}: 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}.

Examples

Sort integers
1
2
declare data=(100 -1 2 3 -10)
echo "Sorting positive and negative integers: " ${(-)data}
Output:
1
Sorting positive and negative integers:  -10 -1 2 3 100
BashSupport Pro 是一款支持 -** 的 **Zsh 集成开发环境 - 立即试用
© 2020–2024 Joachim Ansorg
声明
隐私政策
许可条款