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?
./configure --prefix=$PGENV_ROOT/pgsql-$v $PGENV_CONFIGURE_OPTS
with a comment saying "need to keep a single string to pass to configure or will get an 'invalid package'". But I'm not exactly sure what that's supposed to do, since the unquoted expansion will not stay a single string. (and in any case, theconfigure
scripts I've seen often take some arguments). – ilkkachu Nov 05 '21 at 07:02eval array=("$string")
as a not-optimal way to turn the string into an array. Wven if it's doable assuming the users are trusted, it's not exactly pretty. But in the end that's just as problematic as the script runningsource "$conf"
to evaluate code from another file directly. – ilkkachu Nov 05 '21 at 16:36