uutils/sed

Add `v` command (version assertion)

Open

#397 aberto em 30 de abr. de 2026

Ver no GitHub
 (0 comments) (0 reactions) (0 assignees)Rust (23 forks)github user discovery
good first issue

Métricas do repositório

Stars
 (91 stars)
Métricas de merge de PR
 (Mesclagem média 6d 9h) (25 fundiu PRs em 30d)

Description

Bug

The GNU v command — assert that the running sed is at least a given version — is not implemented. It is essentially a no-op (succeeds if the version is high enough, errors otherwise) and is commonly used at the top of GNU sed scripts as a safety check.

Reproduction

$ echo a | /usr/bin/sed 'v4.0'
a                  # accepted, prints input as usual

$ echo a | ./target/release/sed 'v4.0'
sed: <script argument 1>:1:1: error: invalid command code `v'

Error case (asserting a future version):

$ echo a | /usr/bin/sed 'v9.0'
sed: -e expression #1, char 4: expected newer version of sed

$ echo a | ./target/release/sed 'v9.0'
sed: <script argument 1>:1:1: error: invalid command code `v'

What it should do

From the GNU manual:

v VERSION This command does nothing, but makes sed fail if GNU extensions are not supported, simply because other implementations of sed do not understand it. […] If specified, VERSION must be no newer than the version of GNU sed currently parsing the script; otherwise, the script will be aborted.

Argument is optional. When absent, the command succeeds (just an extension assertion). When present, parse MAJOR[.MINOR[.PATCH]] and compare to a constant in the source.

A reasonable choice for the "current version" constant is 4.8 or 4.9 (matching what GNU advertises) — pick whichever lets the most real-world scripts run unmodified, since the comparison is "no newer than".

Suspected place to add it

src/sed/compiler.rs:1276get_cmd_spec. Add:

'v' => Ok(CommandSpec {
    n_addr: 0,
    handler: compile_version_command,   // new
}),

The handler reads the rest of the line as an optional version string and stashes the version comparison result. Execution is a no-op (the version check happens at compile time and just errors out then).

Rejected under --posix.

Affected GNU testsuite tests

compile-tests, stdin-prog (uses v9 in a probe), and any GNU script in the wild that starts with v.

Guia do colaborador