In Bash, is it possible to pass a variable with a properly-quoted list of options to a command and not have it split on whitespace inside quotes? IOW, this script:
MYCONFIG="--hi FOO=bar 'X=ABC 123'"
printf '[%s]\n' $MYCONFIG
Outputs:
[--hi]
[FOO=bar]
['X=ABC]
[123']
What I would like it to instead output is
[--hi]
[FOO=bar]
['X=ABC 123']
I realize it can be done with arrays or as a function, but I'm working with a script that already depends on the creation of a string variable to hold args. It can't be replaced with a function because other users of the script will get errors.
Is it possible to construct a string with proper quotation to prevent breaking on spaces inside quoted strings?
Failing that, how can I modify the script to support both array configs and existing string configs, perhaps converting the one to the other?