uutils/sed

Add `F` command (print current input filename)

Open

#393 ouverte le 30 avr. 2026

Voir sur GitHub
 (0 commentaires) (0 réactions) (0 assignés)Rust (23 forks)github user discovery
enhancementgood first issue

Métriques du dépôt

Stars
 (91 stars)
Métriques de merge PR
 (Métriques PR en attente)

Description

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.

Guide contributeur