In bash, this sequence doesn't work the way I thought it would:
> command="echo \"foo bar\""
> $command
"foo bar"
Using eval
instead:
> eval $command
foo bar
This does what I want, but I would prefer not to use eval
. Is there any way to formulate the expression "foo bar"
such that the direct invocation $command
sends the single intended argument to echo
, instead of 2 half-quoted arguments?
For context, the script is a simple driver for compiler benchmarking, making it easy to experiment with various compiler options and organize the results for later analysis. There is no presentation factor to be accounted for, only the correct passing of arguments to the compiler, and correct naming of output file paths. Missed quotes lead to errors, whereas superficial factors like spaces are discarded by the compiler frontend and have no effect on the results.
command="echo \"foo bar\""
, you'll only have one space betweenfoo
andbar
, not five, with either approach.