Skip to content

compound-assignment quote state leaks between entries: an apostrophe in one element corrupts the rest, declare d=($h) expands, declare d=(\*) globs a single-quoted string #733

Closed

Description

@caomengxuan666

Summary

Quote state is not contained to the compound-assignment element it belongs to. Three shapes, all from the same family (taxonomy S2: "引号去除→转义解码→字段拆分的阶段顺序无唯一实现;declare/read/alias/直接赋值四入口各一份").

Verified with minimal repros, LF script files, stdout and stderr captured to separate files, oracle = WSL GNU bash 5.3.0. Owner = rubash (reproduced through the engine binary directly, not only through the host).


1. An apostrophe in a "..." element corrupts the quoting of the rest of the literal

h=X
b1=("it's" '$h');   printf '[%s]\n' "${b1[1]}"
b2=("it's" "$h");   printf '[%s]\n' "${b2[1]}"
b1[1] b2[1]
GNU bash [$h] [X]
niu / rubash [X] [$h]

Both directions are wrong: the single-quoted element gets expanded, and the double-quoted one stops expanding. The state flips after the element containing '.

2. declare/local with a single quoted compound body drops the quotes, then expands

h=X
declare d1=('$h');  printf '[%s]\n' "${d1[0]}"
result
GNU bash [$h]
niu / rubash [X]

3. …and then runs pathname expansion on it — a single-quoted glob is globbed

mkdir -p f2d && cd f2d && : > aa.txt
declare d2=('*')
printf 'n=%s e0=%s\n' "${#d2[@]}" "${d2[0]}"
n e0
GNU bash 1 *
niu / rubash 1 aa.txt

This is the one I would fix first: a single-quoted '*' must never be a glob, and here it silently becomes a filename from the cwd. Any declare -a x=('...') whose body contains a glob metacharacter silently changes the data.


Environment / method

Niubash 1.4.0 (rubash git e785c3c8f610), Windows 10 x64 (build 19045). Each shell launched directly against the same LF script file; stdout and stderr written to separate files (> out 2> err) because a single 2>&1 capture interleaves differently and produced a false positive earlier.

Activity

  1. added
    bug
    P1-high
    area:expansion
    family:S2
    on Oct 17, 2026
  2. added a commit that references this issue on Oct 18, 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

    P1-higharea:expansionbugfamily:S2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions