Skip to content

unset: a function sharing the variable's name is removed along with the variable #645

Closed

Description

@SuperYogurt

Summary

unset <name> removes a function that happens to share its name with the
variable being unset. GNU bash keeps functions and variables in separate
namespaces, so unset foo unsets the variable and leaves the function intact;
rubash deletes both.

Reproductions

foo() { echo FN; }; foo=VAR
echo "before: fn=[$(command -v foo)] var=[$foo]"
unset foo
echo "after : fn=[$(command -v foo)] var=[${foo:-unset}]"
GNU : before fn=[foo] var=[VAR]   after fn=[foo] var=[unset]
rub : before fn=[foo] var=[VAR]   after fn=[]    var=[unset]

Because the function is gone, any later call fails:

foo() { echo FN; }; foo=VAR; unset foo; foo
GNU : rc=0    out=<FN>
rub : rc=127  err=<bash: line 1: foo: command not found>

Why it matters

Declaring a state variable and a helper function under the same name is a normal
pattern in shell libraries — the variable records what the helper resolved. With
this behaviour the first unset of that variable silently deletes the helper,
and every later call fails with command not found. The failure is remote from
its cause: the code that breaks is a different line (and often a different file)
from the unset that broke it, and the same code works unchanged on GNU bash.

Observed in the wild: a directory-change hook calls a resolver helper and stores
the result in a variable of the same name. Once a "reset" path ran unset on
that variable, the helper disappeared, and every subsequent cd failed with
line N: <name>: command not found until the library was sourced again.

Environment

niubash / rubash v1.4.0 (official release, Windows x64)

Also reproduced on an older patched build of the same shell.

Expected

unset <name> unsets the variable only. Functions and variables are separate
namespaces, as in GNU bash.

Activity

  1. added
    bug
    P2-medium
    on Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

P2-mediumbug

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions