Skip to content

fix(bootstrap): EXTRA_ARGS expansion produced phantom empty positional arg#3

Merged
Defilan merged 1 commit into
mainfrom
fix/empty-extra-args-expansion
May 23, 2026
Merged

fix(bootstrap): EXTRA_ARGS expansion produced phantom empty positional arg#3
Defilan merged 1 commit into
mainfrom
fix/empty-extra-args-expansion

Conversation

@Defilan

@Defilan Defilan commented May 23, 2026

Copy link
Copy Markdown
Member

What

Change the EXTRA_ARGS expansion in bootstrap.sh from
"${EXTRA_ARGS[@]:-}" to ${EXTRA_ARGS[@]+"${EXTRA_ARGS[@]}"}.

Why

Fixes #2.

Surfaced bootstrapping a fresh Mac Studio on 2026-05-23. The
./bootstrap.sh baseline invocation (no -- passthrough args) failed
with ansible-playbook: error: unrecognized arguments: because the
:- default form was passing a single empty-string positional to
ansible-playbook instead of zero args.

How

The ${arr[@]+"${arr[@]}"} pattern is bash-3.2+ canonical for
'expand to nothing when array is empty, expand to contents
otherwise.' Safe under set -u because EXTRA_ARGS is always
declared as () at the top of the script.

Behavior verified against a mock binary that echoes argc + each arg:

Case argc trailing arg
Old, no extra args 7 [] (empty positional) -- bug
New, no extra args 6 (none)
New, --check -vv 8 [--check] [-vv]

Verification

Mock-bash tested locally. Real end-to-end via ./bootstrap.sh on a
fresh Mac Studio happens immediately after merge.

Checklist

…l arg

bootstrap.sh ended with:

  ansible-playbook ... "${EXTRA_ARGS[@]:-}"

When EXTRA_ARGS=() (the no-`--` invocation, which is the documented
baseline path), `${arr[@]:-}` expands to a SINGLE empty-string
positional argument, not zero arguments. ansible-playbook receives
"" as a trailing positional, doesn't recognize it, and bails with
the unhelpful error 'unrecognized arguments:' (with empty space
after the colon -- the empty string is the bad arg).

The `:-` default form treats arrays the same as scalars: returns
the default string when null/empty. For arrays we want zero
positional args, not the default. The canonical safe form for
bash-3.2+ under `set -u` is:

  ${arr[@]+"${arr[@]}"}

which expands to nothing if the array is unset OR empty, and to
the array contents otherwise. Safe under `set -u` because
EXTRA_ARGS=() is always declared at the top of the script.

Verified with a mock ansible-playbook that prints argc + each
arg:

  ==== old broken behavior ====
  argc=7
    arg[6]=[--diff]
    arg[7]=[]                  <-- phantom empty positional arg

  ==== fixed: empty EXTRA_ARGS ====
  argc=6
    arg[6]=[--diff]            <-- no trailing arg

  ==== fixed: non-empty EXTRA_ARGS=(--check -vv) ====
  argc=8
    arg[6]=[--diff]
    arg[7]=[--check]
    arg[8]=[-vv]

Fixes #2.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] ./bootstrap.sh fails with empty 'unrecognized arguments:' when no extra ansible-playbook args supplied

1 participant