I'm storing the arguments to a command in a variable. The final command I want is:
mock -r myconfig --define "debug_package %{nil}" --resultdir results --rebuild mypackage.src.rpm
Here's my attempt:
set -x # for debugging
RESULTDIR=results
MOCK_CONFIG="myconfig"
MOCK_ARGS="-r $MOCK_CONFIG --define \"debug_package %{nil}\" --resultdir $RESULTDIR"
cmd="mock $MOCK_ARGS --rebuild mypackage.src.rpm"
$cmd
The results are:
+ RESULTDIR=results
+ MOCK_CONFIG=myconfig
+ MOCK_ARGS='-r myconfig --define "debug_package %{nil}" --resultdir results'
+ cmd='mock -r myconfig --define "debug_package %{nil}" --resultdir results --rebuild mypackage.src.rpm'
+ mock -r myconfig --define '"debug_package' '%{nil}"' --resultdir results --rebuild mypackage.src.rpm
ERROR: Bad option for '--define' ("debug_package). Use --define 'macro expr'
As you can see, the arguments to the --define
parameter are not being quoted properly. --define
thinks I'm passing it only debug_package
, which is incomplete.
I have tried various variations in the quotes when defining MOCK_ARGS
, even trying to escape the space between debug_package
and %{nil}
.
What combination of quotes and/or escapes allows me to build this argument list and execute the command from this script?
EDIT:
The reason I'm storing the resulting command in a variable is because it ends up being passed into a function which does some logging, then executes the command.
Also, I have come across this FAQ which suggests I should use arrays instead of a variable. I've begun experimenting with arrays but so far don't have a working solution.