0

I have the next file test.txt with content:

- name: MONGODB_HOST
    value: {{MONGODB-HOST}}

I want to replace {{MONGODB-HOST}} with this env variable:

MONGODB_HOST=server.dev.example,server2.dev.example

Command is:

/bin/sed -i 's,{{MONGODB-HOST}},'"$(MONGODB_HOST)"',' "test.txt";

And it fails:

/bin/sed: -e expression #1, char 56: unknown option to `s'

If I leave:

MONGODB_HOST=server.dev.example

it works. Can you help me find the reason why it is failing?

ovod
  • 103

1 Answers1

5

In your sed command, you're using the , symbol to separate the fields. Your substitution also includes that symbol, so when sed sees that it thinks that's the field separator. Eventually it sees the "real" field separator, and sees content behind it that it doesn't recognize.

Try using a different field seprator; / is a common choice:

/bin/sed -i 's/{{MONGODB-HOST}}/'"${MONGODB_HOST}"'/' "test.txt"
Andy Dalton
  • 13,993