Skip to content

awk: ARGV and ARGC are never set #172

Open

Description

@sylvestre

ARGC is 0 and ARGV is empty, so scripts that read their own arguments in
BEGIN (a very common idiom) see nothing.

Reproduction

Rust (incorrect)

$ ./target/release/awk 'BEGIN { print ARGC; for (i = 0; i < ARGC; i++) print i, ARGV[i] }' one two
0

GNU (correct)

$ gawk 'BEGIN { print ARGC; for (i = 0; i < ARGC; i++) print i, ARGV[i] }' one two
3
0 gawk
1 one
2 two

Test

#[test]
fn argv_and_argc_are_set() {
    ucmd()
        .args(&["BEGIN { print ARGC, ARGV[1], ARGV[2] }", "first", "x=1"])
        .succeeds()
        .stdout_only("3 first x=1\n");
}

Exposed by the GNU awk test suite: argarray, argtest, compare, symtab9.

Activity

  1. added
    bug
    good first issue
    gnu-compat
    on Nov 17, 2026
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