Let's say I have script alpha.sh. The overly simplified version of it is as follows:
#!/usr/bin/bash
ENV_PARAMS_FOR_BRAVO="FOO=bar"
result=$($ENV_PARAMS_FOR_BRAVO bash bravo.sh)
echo $results
And then a script bravo.sh, whose overly simplified version is:
echo "foo is $FOO"
When I run the above alpha script, I get an error, because it tries to execute $ENV_PARAMS_FOR_BRAVO as if it was the command itself. When I run the same exact command replacing the above variable with its contents (result=$(FOO=bar bash bravo.sh)), the script works as expected.
In the actual version of the script, I need to pass a lot more variables to bravo from alpha, so the $ENV_PARAMS_FOR_BRAVO variable is meant to serve as an aggregation for a curated list of arguments for bravo. I also can't pass them to bravo as arguments because many of these are optional and will shift the real arguments bravo takes that are NOT optional.
What's the issue with the above approach and how do I work around it?