I've got this example:

[nir]$ cat a.cfg 
--arg1 $(./get.sh variable)
[nir]$ cat get.sh 
echo "${1}-info"
[nir]$ cat a.sh 
arg=$(cat a.cfg)

echo "$arg"
[nir]$ ./a.sh
--arg1 $(./get.sh variable)

I want the a.sh to return --arg variable-info. the end result is to switch the echo with a real command that takes a.cfg, parse it, and send it as the arguments.

  • Well, with this example, you could replace the whole thing with just a constant string, since a.sh and a.cfg don't take any arguments. That's not what you're looking for, but it's hard to tell which parts of the whole thing here can't be modified (e.g. because they're actually third-party commands). I would probably approach that by changing a.cfg to a script that outputs the required stuff, so you'd use arg=$(otherscript.sh) instead of arg=$(cat otherfile). Running code in there is going to be the end result anyway.
    – ilkkachu
    Jun 16 at 10:56

1 Answer 1


You could have in a.sh:

eval '
arg=$(cat << EOF
'"$(cat a.cfg)"'
printf '%s\n' "$arg"

Which tells the shell to evaluate this shell code:

arg=$(cat << EOF
--arg1 $(./get.sh variable)

And the $(...) will be expanded as it's inside a here-document with unquoted delimiter.

  • Looks like a future rabbit hole :) I think I'm going with placeholder and will calculate ./get.sh variable in the main script. thanks though.
    – Nir
    Jun 16 at 17:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.