Consider this list of version numbers:
0.3.0
0.3.1
...
0.3.8
0.3.9
0.3.10
0.3.11
git tag
would print them in the following ord
serv ~: echo -e "1.1.1\n1.3.2\n1.1.10\n1.1.2" | sort -n -t. -k1,1 -k2,2 -k3,3
1.1.1
1.1.2
1.1.10
1.3.2
Breakdown of the sort
options being used here:
-n
- sort using numerical string order (thus 10
comes after 1
)-t.
- use periods as field separators-k1,1
define a sort key on the first field (and only the first field)-k2,2
define a sort key on the second field (and only the second field)-k3,3
define a sort key on the third field (and only the third field)