ex

shell script replace variables in file - error with Sed's -i option for in-place updating

China☆狼群 提交于 2019-11-27 15:51:44
Here is my test.env 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 error sed: 1: "./config/test.env": invalid command code . sed: 1: "./config/test.env": invalid command code . How can I fix it? tl;dr : With BSD

shell script replace variables in file - error with Sed's -i option for in-place updating

你。 提交于 2019-11-26 17:20:30
问题 Here is my test.env 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 error sed: 1: "./config/test.env": invalid