Skip to content

builtin divergences: dirs -l shape, shift bad-operand status, 3 non-bash builtins (setopt/unsetopt), and 17 more #759

Closed

Description

@caomengxuan666

Summary

A batch of builtin flag / semantics divergences from GNU. Item 1 is the sharpest and I re-verified it myself; items 2–5 are verified here too; the table at the end is the rest of the sweep, agent-verified but not re-checked by me, listed so they can be split out.

Same method throughout: LF script files, ni u (installed 1.4.0, rubash git e785c3c8f610) vs WSL GNU bash 5.3.0, stdout and stderr captured to separate files, byte/count claims decided by python outside the code under test.


1. unset NAME also removes a function of the same name — re-verified

foo=bar
foo(){ echo FUNC; }
unset foo
echo "var=[${foo-<unset>}]"
type -t foo >/dev/null 2>&1 && echo "func=still-there" || echo "func=gone"
variable function
GNU bash unset still-there
niu / rubash unset gone

GNU's unset without -f/-v removes the variable, and only falls back to the function when no variable of that name exists (builtins/set.def). Here the function disappears as well, silently. A script that does cfg=...; cfg(){ ...; }; … unset cfg loses its function and nothing reports it. Sharpest item in the batch — may be worth its own issue.

2. dirs -l prints one entry per line — re-verified

niu:  dirs -l  →  three lines, one path each
      dirs     →  one line, space-separated
GNU:  dirs -l  →  one line, space-separated (same shape as `dirs`)

cat -A confirms the newlines. Any read -r a b c <<< "$(dirs -l)"-style consumer gets a different field count.

3. shift with a bad operand exits 1 — re-verified

( set -- 1 2; shift x )  2>/dev/null; echo $?    # niu 1   GNU 2
( set -- 1 2; shift 1 2 ) 2>/dev/null; echo $?   # niu 1   GNU 2

4. Three builtins exist here that bash does not have — re-verified

niu:  command -v setopt   → setopt
      command -v unsetopt → unsetopt
GNU:  (neither)           (the only hit is the external /usr/bin/sudo)

enable -a line count: 64 (niu) vs 61 (GNU). So setopt and unsetopt are in the builtin table. A script that probes for them to decide "am I under zsh or bash" gets the wrong answer under niu.

(Positive result: the 61 real bash builtin names all agree — command -v / type -t / enable -a match GNU. Nothing is missing.)


Rest of the sweep — agent-verified, not re-checked by me

id builtin form niu GNU
B19 exec exec -a NAME cmd argv[0] unchanged argv[0] = NAME
B03 read read -n/-N with \ in input backslash counts toward N counts emitted chars
B01 printf %b containing \c rc 1 rc 0
B02 printf printf -v with no name error, no usage error + usage
B06 declare declare -p -f on an attributed fn omits declare -fx FN prints it
B07 readonly readonly -p -f FN prints body + declare -fr prints nothing
B08 hash hash fn (fn is a function) not found, rc 1 silent, rc 0
B09 hash hash -l NAME (operand) prints entry prints nothing
B10 hash hash -- NAME invalid option, rc 2 accepted, rc 0
B12 pushd pushd a b pushd: a: No such file pushd: too many arguments
B13 pushd pushd -n <absent> validates and fails rc 1 stores literally, rc 0
B14 source source DIR DIR: No such file source: DIR: is a directory
B17 let let with no args message without trailing newline message + \n
B18 shift (see item 3 above) rc 1 rc 2
B20 enable enable -p NAME enables NAME / errors prints a reusable list, rc 0
B21 enable enable -Z rubash: prefix, no usage, rc 1 SCRIPT: line N: + usage, rc 2
B04 umask umask -- invalid option, rc 2 prints the mask, rc 0

B19 I could not reproduce in my form — with exec -a RENAMED "$BASH" show.sh both shells report $0 as the script name, which is correct for a script file; the sweep's form must differ, so treat B19 as reported-only.

B15/B16 (the eval, let and (( … )) diagnostics ignoring an fd-2 redirection) are not filed here — they are additional emitters for #726, and are noted there.

Ruled out by the sweep as non-bugs (recorded so nobody re-derives them)

  • test -L/-h on symlinks: ln -s fails with Operation not permitted on Windows, so no symlink exists to test.
  • -nt/-ot/-ef: an earlier diff was DrvFs 1-second mtime granularity; re-probed with a sleep 2 gap → byte-identical.
  • type -a / command -v path strings, ulimit -a values, compgen -A user/group/hostname, times, help -m: host environment, not semantics.
  • enable -f foo.so: no dlopen on Windows.

Method

LF .sh probes written with a file, run as niu <file>; oracle WSL GNU bash 5.3.0 entered through a tr -d '\r' copy; a marker asserted in both arms so a broken arm cannot read as a difference; stdout/stderr to separate files; byte claims by python.

Activity

  1. added
    bug
    P2-medium
    area:builtins
    on Oct 17, 2026
  2. caomengxuan666 commented on Oct 17, 2026

    @caomengxuan666
    MemberAuthor

    Correction — item 1 is a duplicate of a closed issue, already fixed, and already has a regression test

    My apologies for the noise. Item 1 (unset NAME also removing a same-named function) is #645, which is closed, and the fix is not in the build I measured:

    installed build : e785c3c8   2026-10-14 11:19  (what `niu -V` reports as e785c3c8f610)
    fix             : 47837007   2026-10-16        "fix(unset): preserve same-named functions"
    
    $ git merge-base --is-ancestor 47837007 e785c3c8f610   → not an ancestor
    $ git show --stat 47837007
        src/executor/unset_arrays.rs                        |  5 +++++
        tests/issue645_unset_function_regressions.rs        | 33 +++++++++++
    

    So the fix landed two days after the build I tested, and it came with its own regression test. Item 1 should be treated as fixed on HEAD, verified by your issue645_unset_function_regressions.rs — please close/ignore that part of this issue, and I will re-run the whole case set against a near-HEAD build rather than report from a three-day-old release again.

    Two other items also need re-labelling

    What is genuinely new here

    From the duplicate sweep: setopt/unsetopt, promptvars, and compgen -A signal returned no other issue in the tracker, so items 4 (setopt/unsetopt in the builtin table), B11 (dirs -l shape) and the rest of the table appear to be new.

    Method note for anything from me from now on

    Every finding I filed up to #759 was measured against e785c3c8 (2026-10-14). Anything fixed after that date will look broken in my reports. Going forward I will re-run against a build from the current master and state the commit in the issue, the way the invocation sweep already did (it separated "installed only" from "persists at ea9c18e8").

  3. changed the title [-]builtin divergences: unset NAME also deletes a same-named function (plus dirs -l shape, shift status, 3 non-bash builtins, and 17 more)[/-] [+]builtin divergences: `dirs -l` shape, `shift` bad-operand status, 3 non-bash builtins (setopt/unsetopt), and 17 more[/+] on Oct 17, 2026
  4. caomengxuan666 commented on Oct 17, 2026

    @caomengxuan666
    MemberAuthor

    先处理了第 1、2、3 项,提交 5da6421。

    项 1 unset 连函数一起删 —— 当前 master 已不复现

    foo=bar; foo(){ echo FUNC; }; unset foo
    # var=[<unset>] func=still    ← 与 GNU 一致
    

    应该是这期间别的提交带掉的(issue 记录的基线是 e785c3c8)。这条可以划掉。

    项 2 dirs -l 逐行 —— 已修

    -l 被当成 -p 处理了。-l 是 long form,只影响 $HOME 折不折成 ~,分隔符仍是单个空格;只有 -p(以及本来就逐行的 -v)才一个一行。rubash 的栈本来就存全路径,所以 -l 根本没有单独渲染,不该置 printable。

    形态 修后 GNU
    dirs /usr /tmp(一行) 同
    dirs -l /usr /tmp(一行) 同
    dirs -p 逐行 同
    dirs -v 逐行带编号 同
    dirs -l -v 与 dirs -v 相同 同

    回归测试 dirs_long_form_keeps_the_space_separator。

    项 3 shift 坏操作数状态 —— 在 5.2.21 上与 GNU 一致,暂不动

    issue 里记的是 GNU 5.3.0 给 2。我这边沙箱 GNU 是 5.2.21,实测:

    ( set -- 1 2; shift x )   2>/dev/null; echo $?   -> bash 1  rubash 1
    ( set -- 1 2; shift 1 2 ) 2>/dev/null; echo $?   -> bash 1  rubash 1
    

    两边一致,所以在你记录的 5.3.0 基线上可能是版本行为变化。需要一份 5.3.0 的输出再定,暂时不改(改了反而会和 5.2.21 分叉)。

    项 4 setopt/unsetopt —— 没动

    这两个是 zsh 名字,但从 builtin_direct_command.rs 看是有意加的(execute_zsh_option_builtin),删掉会动到现有行为。这是产品决策,等你定:要么删掉让"是不是 bash"的探测正确,要么保留并写进文档说明是 niubash 扩展。

    表格里其余 17 项

    没动。等这批单点清完再按需拆。

  5. added 2 commits that reference this issue on Oct 18, 2026
  6. added a commit that references this issue on Nov 1, 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

    P2-mediumarea:builtinsbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions