• Intro Headers Instructions Macros Commands
Fork me on GitHub
    • Getting Started
      • Introduction
      • How to install bnd
      • Guided Tour Workspace & Projects
      • bnd / bndlib Features and JAR Wrapping Techniques
      • FAQ - Frequently Asked Questions
    • Concepts and Practices
      • Concepts
      • Background
      • Best practices
    • Build and Development
      • Build
      • Generating JARs
      • Versioning
      • Baselining
      • Service Components
      • Metatype
      • Contracts
      • Bundle Annotations
      • Accessor Properties
      • SPI Annotations
    • Dependency and Launching
      • Resolving Dependencies
      • Launching
      • Startlevels
    • Testing
      • Testing
      • Testing with Launchpad
    • Packaging and Distribution
      • Packaging Applications
      • JPMS Libraries
      • Wrapping Libraries to OSGi Bundles
    • Documentation and Tools
      • Generating Documentation
      • bnd CLI Commands
      • For Developers
      • Templates for Workspaces
      • Tips for Windows users
      • Tools bound to bnd
    • Reference Material
      • Reference
      • Headers
      • Instruction Reference
      • Instruction Index
      • Macro Reference
      • Macro Index
      • Plugins
      • External Plugins
    • Configuration and Troubleshooting
      • Settings
      • Errors
      • Warnings
  • nsort (';' LIST )+

    Prev Next
    Macro
    Sort lists numerically by treating values as numbers

    Summary

    The nsort macro combines one or more lists and sorts their contents numerically. Unlike alphabetic sorting, it treats values as numbers, so “2” comes before “10”.

    Syntax

    ${nsort;<list>[;<list>...]}
    

    Parameters

    • list - One or more semicolon-separated lists to sort (items within lists are comma-separated)

    Behavior

    • Combines all provided lists into a single list
    • Strips leading zeros from values for comparison
    • Sorts primarily by numeric length (shorter numbers first)
    • For values of equal length, sorts lexicographically
    • Returns a comma-separated sorted list

    Examples

    Sort numbers correctly:

    ${nsort;10,2,1,20,3}
    # Returns: "1,2,3,10,20" (not "1,10,2,20,3")
    

    Sort with leading zeros:

    ${nsort;001,010,002,100}
    # Returns: "1,2,10,100" (leading zeros removed)
    

    Combine and sort multiple lists:

    ${nsort;5,15,25;10,20,30}
    # Returns: "5,10,15,20,25,30"
    

    Sort version-like numbers:

    ${nsort;1,11,2,21,3}
    # Returns: "1,2,3,11,21"
    

    Use Cases

    • Sorting version numbers or identifiers
    • Ordering numeric strings correctly
    • Sorting file numbers or indices
    • Version lists in proper numeric order
    • Port numbers or numeric identifiers
    • Any list where numeric order matters

    Notes

    • Sorts by length first, then lexicographically
    • Leading zeros are stripped before comparison
    • All values are treated as strings during comparison
    • Shorter numbers always come before longer numbers
    • For equal-length values, uses string comparison
    • See also: ${sort} for alphabetic sorting
    • See also: ${vcompare} for semantic version comparison

    See test cases in MacroTestsForDocsExamples.java

Prev Next
Search
    • Home