Skip to content

awk: a missing input file is silently ignored and the exit status is 0 #180

Closed

Description

@sylvestre

Reproduction

Rust (incorrect)

$ ./target/release/awk 'END { print NR }' missing.txt; echo $?
0
0

GNU (correct)

$ gawk 'END { print NR }' missing.txt; echo $?
gawk: fatal: cannot open file `missing.txt' for reading: No such file or directory
2

Test

#[test]
fn missing_input_file_is_fatal() {
    ucmd()
        .args(&["END { print \"end\" }", "no-such-input"])
        .fails_with_code(2)
        .stderr_contains("no-such-input")
        .no_stdout();
}

Exposed by the GNU awk test suite: nofile.

Activity

  1. added
    bug
    good first issue
    gnu-compat
    on Nov 17, 2026
  2. Alonely0 commented on Nov 18, 2026

    @Alonely0
    Collaborator

    Codebase context: src/event.rs, function rule_event_loop() calls begin_file_event_loop(), which passes errors to the VM by calling begin_file_prelude() in interpreter/src/vm/io.rs. This function's task is, among other things, to handle the error and set the values of the appropriate built-in variables; the error is only critical if PROCINFO is not set to non-fatal input.

    I will add some doc comments and TODOs about this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buggnu-compatgood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions