Skip to content

[bug] set -a does not mark a scalar assignment over an existing indexed array #2963

Closed

Description

@caomengxuan666

Summary

Under set -a, a scalar assignment over an existing INDEXED array does not take the export mark in rubash, while GNU marks it. The associative twin already matches (both shells show -Ax), so the gap is specific to the indexed scalar-over-array bind arm. Found while probing the r79 batch (Refs #2944 / #2945); it is a different bind arm from those issues and is filed separately rather than folded into that batch.

Reproduction (master 4f74741)

set -a; arr[0]=x; arr=abde; declare -p arr
  • GNU bash 5.3.20: declare -ax arr=([0]="abde")
  • rubash: declare -a arr=([0]="abde")

Control shapes that AGREE on both shells:

  • set -a; declare -A m=([k]=v); m=scalar; declare -p m → declare -Ax m=([0]="scalar" [k]="v" ) on both.
  • arr[0]=x; export arr; arr=abde; declare -p arr (pre-exported, no set -a) → declare -ax on both, and printenv arr fails on both (an array's value never crosses the env boundary in either shell — only the ATTRIBUTE diverges).

GNU semantics

A scalar value bound over an existing array still goes through bind_variable (variables.c), whose tail applies the mark_modified_vars mark (variables.c:3211-3212) while set -a is on (flags.c:47,167) — the array's assign_func stores element 0, but the bind itself is a scalar bind for marking purposes. The associative leg of rubash's assignment path already mirrors this; the indexed leg's arm (the element-0 write path in the assignment executor) projects the value into the process env instead of setting the export attribute.

Regression seed

set -a
arr[0]=x
arr=abde
declare -p arr   # GNU: declare -ax arr=([0]="abde")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area:builtinsbuggnu-baseline

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions