Skip to content

builtins/expansion: printf numeric validation, command -v multi-operand status, ~+/~-/~user in assignments, type -a ordering, BASH_ARGC/HISTCMD #704

Closed

Description

@caomengxuan666

Summary

Five builtin / expansion divergences from GNU bash. Individually small, but each is deterministic.

Environment: Niubash 1.4.0 · rubash git e785c3c8f610 — Windows 10 x64.
Method: differential vs GNU bash 5.2.21(1) / 5.3.0.


R6.1 printf numeric conversion: trailing whitespace not treated as invalid

$ printf '%d\n' '5 ' ; echo "rc=$?"
niu : 5   (no diagnostic)  rc=0
bash: 5 + "printf: 5 : invalid number"  rc=1

$ printf '%f\n' '5 '
niu : 0.000000             rc=1
bash: 5.000000             rc=1

$ printf '%d\n' $'5\t'  ;  printf '%o\n' '5 '
niu : accepted silently (same as '5 ')
bash: invalid number, rc=1
  • Affects %d %i %x %o %u.
  • Leading whitespace (' 5') matches on both (accepted).
  • Trailing tab / newline also affected.
  • For %f the value is dropped to 0.000000 instead of kept.

R6.2 command -v with multiple operands: exit status uses "all found" instead of "any found"

$ command -v echo nosuch_xyz >/dev/null ; echo $?
niu : 1
bash: 0      # bash returns 0 if ANY operand is found

Exhaustive: missing+found in any position → niu 1, bash 0; all missing → both 1; all found → both 0. type agrees between shells, so this is specific to command -v.


R6.3 Tilde expansion in assignment context: ~+, ~-, ~user not expanded

$ OLDPWD=/foo; A=~+; B=~-; C=~root; echo "A=[$A] B=[$B] C=[$C]"
niu : A=[~+] B=[~-] C=[~root]        # literal
bash: A=[$PWD] B=[/foo] C=[/root]
  • Word position works in niu: echo ~+ expands.
  • ~ and ~/path in assignments match bash.
  • Only the ~+ / ~- / ~user prefixes fail, and only in assignment position. (~user also has no passwd db on Windows — but ~+/~- need no db and still fail.)

R6.4 type -a ordering disagrees with actual resolution (Windows PATHEXT)

With a PATH directory containing both extensionless tool and tool.bat:

$ type -a tool      # niu: lists  .../tool  FIRST, then .../tool.bat
$ command -v tool   # niu: .../tool.bat
$ tool              # niu: runs tool.bat

type -a reports the extensionless file first while command -v and execution both pick tool.bat — internally inconsistent. On GNU/Linux type -a correctly lists only the extensionless file. (niu can run extensionless files when they are the only match, so type -a is actively misleading here, not merely extra.)


R6.5 BASH_ARGC frame stack incomplete; HISTCMD unset

$ echo "HISTCMD=[${HISTCMD-<unset>}]"; echo "top argc_n=${#BASH_ARGC[@]}"
niu : HISTCMD=[<unset>] top argc_n=0
bash: HISTCMD=[0]       top argc_n=1

$ shopt -s extdebug; f(){ echo "fn argc=[${BASH_ARGC[*]}] n=${#BASH_ARGC[@]}"; }; f AA BB
niu : fn argc=[2] n=1
bash: fn argc=[2 0] n=2

BASH_ARGV matches on both; only BASH_ARGC (frame stack) and HISTCMD differ.

Activity

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

    @caomengxuan666
    MemberAuthor

    Version note (correction to the Method line): the oracle was reached with bare wsl.exe -e bash, which resolves through PATH to /usr/local/bin/bash = GNU bash 5.3.0(1) — not 5.2.21. The 5.2.21 build lives at /bin/bash, and every item in this report was re-checked on it as well; results were identical on both.

    So the two versions are listed in the wrong order above: 5.3.0 was the default, 5.2.21 the cross-check.

    No finding here changes; noting it only so the numbers reproduce. (Incidentally 5.3.0 is also the oracle cited in rubash#641, "the repository oracle is WSL 5.3.0".)

  3. added
    area:builtins
    family:S1
    on Oct 17, 2026
  4. caomengxuan666 commented on Oct 17, 2026

    @caomengxuan666
    MemberAuthor

    Duplicate-sweep note: the ~ item here is a residue of closed issues, not a new class

    I swept the tracker for closed predecessors of everything I filed, and this one's second item is not new:

    this item closed predecessor relationship
    ~+ / ~- / ~user in an assignment (x=~root, x=~+) #550 格1 — echo ~root:x not expanded in a command word (closed 2026-10-12, labelled platform) same contract, different position
    quoted "~/" handling #523 — compgen -d -- "~/" quoted tilde-slash not expanded (closed 2026-10-12) same contract, completion entry point

    Both predecessors are closed, and the expansion still fails from a third position (an assignment RHS). Same shape as the other families in the sweep: the item gets closed at the reported entry point, and the class stays open at the others. Worth treating as one "tilde expansion positions" family (word → assignment → completion) rather than three separate fixes.

    Not a duplicate claim — this issue stays open. Flagging it so triage can decide whether to re-open #550 or fold the position sweep into it.

  5. caomengxuan666 commented on Oct 17, 2026

    @caomengxuan666
    MemberAuthor

    先修了 R6.2,提交 5da6421。

    R6.2 command -v 多操作数 —— 已修

    根因不在 builtins/command.rs(那里的 any_found 逻辑本来是对的),而在 executor/type_builtin.rs 的 execute_command_describe_with_io:它和 type 共用了一个"任一缺失就置 1"的累加器。command 的 -v/-V 走这条路径,type 不走。

    GNU builtins/command.def 是 any-found(if (describe_command (...) == 0) any_found++),type 是 all-found。现在 command 这条改成 any_found,-V 的逐操作数 "not found" 诊断保留。

    形态 修前 修后 GNU
    command -v echo nosuch_xyz 1 0 0
    command -v nosuch_xyz echo 1 0 0
    command -V echo nosuch_xyz 1 0 0
    command -v nosuch1 nosuch2 1 1 1
    type echo nosuch_xyz(对照) 1 1 1

    回归测试 command_describe_multi_operand_uses_any_found。

    剩余四项未动

    • R6.1 printf 尾随空白当合法数字:需要改 %d %i %x %o %u 的转换校验和 %f 的取值路径,涉及面比"加个 trim 判断"大(%f 现在还会把值丢成 0.000000),单独一轮做。
    • R6.3 赋值上下文里的 ~+/~-/~user:tilde 展开在赋值位走的是另一条入口,要单独接。
    • R6.4 type -a 的 PATHEXT 顺序:这是 Windows 路径解析与 command -v 不一致,属路径层。
    • R6.5 BASH_ARGC / HISTCMD:需要看 frame stack 和交互历史是否具备前置条件。

    issue 先留着。

  6. added a commit that references this issue on Oct 19, 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:builtinsbugfamily:S1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions