29

gir.st - A one-liner version number incrementor

 4 years ago
source link: https://gir.st/blog/inc-version.htm
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

A one-liner version number incrementorHome | Blog | inc_version

A one-liner version number incrementor

For a project I'm maintaining I've written a release script, after bodging one too many releases. For this, I came up with this helpful little snippet to increment version numbers.

inc_version() {
	awk -F. -vOFS=. '{ $ver++; while(ver++<NF) $ver=0; print $0 }' ver=$1
}

You just give it a version number on stdin, tell it which part you need incremented, and you'll get it properly changed on stdout. Fields right of the one given get zeroed out.

echo "1.2.3" | inc_version 3
1.2.4

echo "1.2.3" | inc_version 2
1.3.0

echo "1.2.3" | inc_version 1
2.0.0

If your version number ends on a build- or version control identifier, just replace NF with NF-1, so the zeroing stops one field short.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK