Resolving env inside another env

So i would like to print my env variable which contains other variables.
For example i have:

MY_VARS="My var are:\nVAR1 = ${MY_VAR1}\nVAR2 = ${MY_VAR2}"

and i would like to make it possible in way like:

  • Docker ERROR: Container command not found or does not exist when running from Win10
  • Why is Internal memory in java Native Memory Tracking increasing
  • Docker: unable to execute the mount command inside an ubuntu 16.10 container [duplicate]
  • Sharing docker clusters
  • apt-get fails in Debian and Ubuntu based docker images
  • Build a docker image from vagrant
  • printf "${MY_VARS}" > my.conf


    printf "$(echo ${MY_VARS})" > my.conf

    to get sth like in my.conf file:

    My var are:
    VAR1 = var1
    VAR2 = var2

    but it dosent work.
    Is ther possibility to do such thing ?
    I need it to us it with Kubernetes so i can set env in my ReplicationController and use it with Kubernetes envs like SERVICE_HOST and SERVICE_PORT
    There is another problem that Kubernetes is changing my MY_VARS variable to multiline inside container so it looks like:

    MY_VARS=My var are:
    VAR1 = ${MY_VAR1}
    VAR2 = ${MY_VAR2}

    Hope it’s quite clear 🙂

    My solution:

    while read -r line
      printf "$line\n" >> conf.tmp
    done <<< "$CONFIG"
    while read -r line
      eval echo $line >> conf
    done < conf.tmp

    Where CONFIG variable is passed by me to the container and this variable contains Kubernetes service variables with IPs and Ports.
    I had to make it twice because eval couldnt resolve \n.

  • All images and containers disappeared after host kernel downgrade
  • Network path between containers in custom network
  • How to run multiple agents in multiple Minecraft environment with python threading in docker container?
  • How critical is dumb-init for Docker?
  • Mysql in container or different VM
  • Increasing mysql max_connections to 1024 in a docker container
  • 2 Solutions collect form web for “Resolving env inside another env”

    With bash you can perform indirect references but it would not replace the value of your variable directly, only when you use it from a bash terminal.

    You’ve got to define the vars first. The following script prints out what you want:

    MY_VARS="My var are:\nVAR1 = ${MY_VAR1}\nVAR2 = ${MY_VAR2}"
    printf "${MY_VARS}"
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.