You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
unset: a function sharing the variable's name is removed along with the variable #645
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.
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