A bash script I have limited or no ability to modify is using an environment variable like:
"${SERVER_ADDRESS}"
The actual SERVER_ADDRESS value can only be determined dynamically at runtime so I would like to set SERVER_ADDRESS to a curl command that looks up the IP. Something like:
SERVER_ADDRESS='curl -s http://lookup.api.com'
What makes this more complicated is that the actual lookup will only return a part of the necessary address, so what I really need is some kind of concatenation:
SERVER_ADDRESS='$(curl -s http://lookup.api.com).restofaddress.com'
This will mean that the curl command will be run and evaluated when the string is assigned to the environment variable, however, I need that evaluation to take place in the script when it's run.
I have tried every possible way of formatting the text in that environment variable so that the script with just "${SERVER_ADDRESS}" will end up with the correct value, but I'm stumped. Perhaps it's simply not possible without adding a little more sophistication to the receiving script.
/bin/bash /path/to/script.sh
, can you call it likeSERVER_ADDRESS="$(curl -s http://lookup.api.com).restofaddress.com" /bin/bash /path/to/script.sh
? – jayhendren Dec 12 '16 at 19:21