[Solved] Replace var placeholder results in an unwanted new line

progonkpa Asks: Replace var placeholder results in an unwanted new line
I wish to replace ${var} placeholders in a nginx.conf file with env vars loaded from .env file (docker). I choose the ${var} syntax myself in line with docker-compose.

content .env file:

Code:
DOMAIN_NAME=sub.domain.org
DB_USER=admin
...

Doing sed string replace on this line e.g. is giving me headaches.

Text input:
server_name ${DOMAIN_NAME};

command:

Code:
source .env

export DOMAIN_NAME

sed -i "s/${DOMAIN_NAME}/$DOMAIN_NAME/g" "$docker_root"/nginx/nginx.conf

desired outcome:
server_name domain.net;

but what I get is:

Code:
server_name domain.net
;

It doesn’t even matter what follows the ${var} replacement. If I add a space and a word behind the placeholder, the word also ends up on the second line.

I used envsubst first and saw the same behavior there first.
Then I tried with sed wich is doing the same :)

I tried a variety of escape slashes, single quotes and double quotes with no result.

What’s going on here?

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.