In a CI/CD job, I have a shell variable X defined.  It contains one or more words, each of which might have glob operators:
X="foo bar* 'a b c'"
Suppose bar* matches 3 files, bard, bare, and barf.  And the file a b c exists and has 2 spaces in it.
I want to create a Bash array Y with these contents:
Y=(--arg foo --arg bard --arg bare --arg barf --arg 'a b c')
In other words: do glob/quote expansion, then map each word w to --arg $w.
A clean solution would allow spaces in the expanded names (to be honest, I'm never going to have that situation in this CI/CD code - but I or someone else might easily copy/paste this technique somewhere else where it does matter).
It would also be awesome if I could do glob/quote expansion without invoking all other possible shell expansions (e.g. process substitution & subshells) - I'm having trouble thinking of how to do that, though.
The only solution I've come up with so far is to use unprotected expansion:
Y=()
for a in $X; do
    Y+=(--arg "$a")
done
Is that the best I can do?  Is it safe?  It works well on the foo and bar* cases, but not well on the a b c case.
 
     
     
    