Skip to content

管道中未加引号变量作命令字不分词:$v | cat 把整串当成一个命令名 #68

Closed

Description

@caomengxuan666

复现

v="echo hi there"
$v | cat

实际输出(niu 1.0.1 / rubash master 355f8a6,Windows / winuxcmd 1.0.0):

niu: line 1: echo hi there: command not found

期望(GNU bash):输出 hi there —— 未加引号的 $v 必须做 field splitting,echo 作为命令名。

影响范围

  • 管道任意段的命令字位置(第二段同样失败):echo pre | $v → echo hi: command not found
  • 子 shell:( $v | cat )
  • 花括号组:{ $v | cat; }
  • 进程替换:while read -r l; do echo "$l"; done < <($v | cat)
  • 顶层简单命令正常:$v 单独执行时正确分词

真实脚本受害案例

git-summary (MirkoLedda) 的 list_repos:

find_cmd="find -L $1 -maxdepth 2 -type d -name .git -print0"
while IFS=  read -r -d $'\0'; do
  git_directories+=("$REPLY")
done < <($find_cmd | sort -z 2>/dev/null)

$find_cmd 整串被当成一个命令名 → find -L ... : command not found,脚本失效。

Activity

  1. caomengxuan666 commented on Sep 7, 2026

    @caomengxuan666
    MemberAuthor

    已在 5a4fddc 修复:管道各级(含 builtin/external 分派)对展开后的首词按 GNU bash 语义做域分割,剩余字段作为前导参数。验证: → "hi there";第二段、子 shell、brace group、进程替换内均正确。

  2. added
    bug
    area:expansion
    on Oct 17, 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

    area:expansionbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions