uutils/sed

Add `F` command (print current input filename)

Open

#393 创建于 2026年4月30日

在 GitHub 查看
 (0 评论) (0 反应) (0 负责人)Rust (23 fork)github user discovery
enhancementgood first issue

仓库指标

Star
 (91 star)
PR 合并指标
 (PR 指标待抓取)

描述

Bug

The GNU F command — print the current input filename, followed by a newline — is not implemented.

Reproduction

$ echo abc | /usr/bin/sed -n 'F' /etc/hostname
/etc/hostname

$ echo abc | ./target/release/sed -n 'F' /etc/hostname
sed: <script argument 1>:1:1: error: invalid command code `F'

What it should do

From GNU sed manual:

F Print out the file name of the current input file (with a trailing newline).

Behaviour notes:

  • Output goes to stdout (like =, p).
  • For stdin, GNU prints -.
  • Honors -z (NUL-separated output) — see nulldata.sh.
  • Accepts an address range like other GNU extensions.
  • Rejected under --posix (already handled by the existing bad_command(OPT) path; once F is added, the --posix rejection test in compile-errors will keep working as expected).

Suspected place to add it

src/sed/compiler.rs:1276get_cmd_spec:

'F' => Ok(CommandSpec {
    n_addr: 2,
    handler: compile_empty_command,   // F takes no args
}),

…plus a corresponding execution case in src/sed/processor.rs (search for the match cmd.code near processor.rs:635). The processor already has access to the current input filename via the same path that -i uses to compute backup names — see src/sed/in_place.rs for how filenames are tracked.

Affected GNU testsuite tests

follow-symlinks, nulldata. Also unblocks the F parts of follow-symlinks-stdin.

贡献者指南