Treat $_ as a special variable

"Listeria monocytogenes" <[email protected]> Wed, 22 Oct 2025 14:18:13 +0000
Newsgroups org.kernel.vger.dash
Message-ID <[email protected]>
Hello,

The current treatment of the $_ variable leads to spilling the last
argument from a command into the environment of the next when dash is
invoked interactively from bash or zsh, as in:

  bash$ dash
  dash$ echo hello
  hello
  dash$ env | grep ^_=
  _=hello

This is because bash exports _=/usr/bin/dash (or whatever the full
pathname used to invoke dash is) into dash's environment, which in turn
sets it to the last argument of the previous command, but as it has been
exported, it spills into the environment of the next command.

Currently, this can be mitigated by executing `unset _` in $ENV, but
this would not be a problem if $_ were treated as a special variable, as
its value in the environment would remain unmodified.