Skip to content

[bug] Special variable $_ is never updated by command execution (: "ARG"; echo $_ keeps startup value) — pure-bash-bible trim_string/urlencode corrupt #321

Closed

Description

@caomengxuan666

Found by ecosweep3 lane (pure-bash-bible corpus, sections 001/013; carrier release build of 6106961).

Reproducer (target/probe-out/p1.sh)

: "ARGVAL"
echo "[$_]"
  • GNU bash 5.3.0 (WSL, script file): [ARGVAL]
  • rubash: [./release/rubash.exe] (startup value of $_; never updated)

Impact (corpus evidence)

  • pbb trim_string: : "${1#...}"; printf '%s\n' "$_" prints the timeout.exe path instead of the trimmed string (section 001).
  • pbb urlencode: for ((...)); do : "${1:i:1}"; case "$_" in ... — $_ stays at the last local LC_ALL=C argument ("C"), so every character percent-encodes as %43 (section 013).

GNU anchor

execute_cmd.c:4194 var = bind_variable ("_", arg, 0); (also 4181 read site): after each simple command bash binds $_ to the last word of the expanded command. variables.c sv table owns the export side.

Expected

$_ tracks the last argument of the last executed simple command (incl. : builtins and assignment-prefixed commands).

Activity

  1. added
    bug
    gnu-baseline
    on Sep 29, 2026
  2. added 3 commits that reference this issue on Sep 29, 2026
  3. caomengxuan666 commented on Sep 29, 2026

    @caomengxuan666
    MemberAuthor

    Fixed by wt14/pbbfix (77d49f8, master): $_ was bound only into env_vars (shadowed by the typed variable store), pure assignments never bound the empty string, function calls did not rebind to the invocation word, and bare ((...)) bound )) - the full GNU bind-point coverage ported (execute_cmd.c:4746/4943/4188 incl. the NULL-binds-empty-string rule at :4638, variables.c:543). 14-form command matrix + comsub/subshell isolation + pbb trim_string/urlencode end-to-end byte-identical. Whole-suite failure set moved 258 -> 257 with the single delta being an existing RED test turning GREEN.

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-baseline

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions