Shell script replace variables in file - error with Sed's -i option for in-place updating
Here is my test.env file:
RABBITMQ_HOST=127.0.0.1
RABBITMQ_PASS=1234
And I want to use test.sh to replace the value in test.env to:
RABBITMQ_HOST=rabbitmq1
RABBITMQ_PASS=12345
Here is my test.sh:
#!/bin/bash
echo "Hello, World!"
RABBITMQ_HOST=rabbitmq1
RABBITMQ_PASS=12345
Deploy_path="./config/test.env"
sed -i 's/RABBITMQ_HOST=.*/RABBITMQ_HOST='$RABBITMQ_HOST'/' $Deploy_path
sed -i 's/RABBITMQ_PASS=.*/RABBITMQ_PASS='$RABBITMQ_HOST'/' $Deploy_path
But I have an error
sed: 1: "./config/test.env": invalid command code .
sed: 1: "./config/test.env": invalid command code .
How can I fix it?