I've created a bash script that gets an IP Address as variable ${MYSQL_SERVER_IP}. I then want to pass it in a sed to replace the previous IP address in a settings.py file. Here is the closest I have gotten to a sed statement that actually runs without error:
export MYSQL_SERVER_IP= '172.19.0.2'
sed -i -e '/DB_HOST =/c\DB_HOST = os.getenv( '\''IP'\'', '\''${MYSQL_SERVER_IP}'\'')\' Flask-URL-Shortener/settings.py
The problem is that the script doesn't replace the variable with the value of the variable.
In the file before running the script:
DB_HOST = os.getenv( 'IP', '172.31.0.2')
Currently the output I get is wrong:
DB_HOST = os.getenv( 'IP', '${MYSQL_SERVER_IP}')
as I would like to obtain the following output:
DB_HOST = os.getenv( 'IP', '172.19.0.2')
This sed statement is the last line of code I need to fix to make my program work the way I want it to.
/\DB_HOST =\**/matchesDB_HOST =followed by zero or more*; is this your intention? (By the way it works just because\Dis not special, so `` is actually ineffective.)DB_HOST = os.getenv( 'IP', '${MYSQL_SERVER_IP}')is what you currently get upon using your broken command (because you wrote Current replacement), and thatDB_HOST = os.getenv( 'IP', '172.19.0.2')is what you want to get (because you wrote Desired). @WilliamPursell, in his answer, assumes thatDB_HOST = os.getenv( 'IP', '${MYSQL_SERVER_IP}')is what you have in yoursettings.pyfile before editing it. Can you please clarify this? Besides, as I already wrote in a comment, please stop writing code in the comments and edit your question.