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:

  • bcrypt and Docker bcrypt_lib.node: invalid ELF header
  • How to edit source code of a python project deployed in docker
  • Docker Add/Copy subdirectory separately
  • How to use the docker remote API?
  • Enabling logging for rabbit mq server within a docker image
  • Can't npm install dependencies when building docker image
  • 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.

  • How to dockerized java microservices efficiently
  • How do I run a docker container based on its name from `docker ps -a`?
  • docker—run nginx not allways working
  • How to install Material Design Lite Documentation Offline?
  • Docker doesn't seem to be mapping ports
  • Trying to install Mezzanine via Docker
  • 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.