Search

Dark theme | Light theme

April 2, 2026

Nushell Niceties: Check Semantic Version Is A Match

In a previous blogpost you can learn about the semver command in Nushell to transform a string value into a semver type. The command has a subcommand match-req. You can use this command to check if a version matches part of the semantic version parts. The result is a boolean value. The version to compare with doesn’t have to defined fully, but could exist of only the major, minor or patch parts. The value you pass can also be used to check if a version is greater or smaller than a given version. A range with a lower and upper version to match on can be defined as well. The boundary values are separated by a comma.

In the following example the command semver match-req is used with different values:

use std/assert

plugin use semver

let version = '4.0.2'

assert ($version | semver match-req '4.0.2')
assert ($version | semver match-req '4')
assert ($version | semver match-req '4.0')

assert ($version | semver match-req '>=4')
assert ($version | semver match-req '>3')
assert ($version | semver match-req '<5')
assert ($version | semver match-req '>4.0.1')

assert ($version | semver match-req '>3,<5')
assert ($version | semver match-req '>=4.0,<4.1')

assert not ($version | semver match-req '3')
assert not ($version | semver match-req '>5')
assert not ($version | semver match-req '<4')

Written with Nushell 0.111.0.