shell - Access Host Variable inside a inline echo command in Linux Script -


all, running shell script on ec2 instance. , trying define service ip of instance.

    my_ip=$(curl http://169.254.169.254/latest/meta-data/local-ipv4)      echo '{"service": {"name": "demo", "tags": ["demo"], "port":80, "check":{"script":"curl $my_ip:80 >/dev/null 2>&1","interval":"10s"}}}' | sudo tee /etc/demo.json 

when browse demo.json file on instance, my_ip variable not getting replaced.

could please help.

your argument echo quoted using single quotes. these prevent evaluation of shell variables $my_ip, inside there verbatim (as $my_ip).

you have close single quotes, insert "$my_ip", open single quotes again:

echo '{"service": {"name": "demo", "tags": ["demo"], "port":80, "check":{"script":"curl '"$my_ip"':80 >/dev/null 2>&1","interval":"10s"}}}' | sudo tee /etc/demo.json 

Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -