0

I have .env file that needs to updated dynamically with a shell script from the user input. SPRING_DATASOURCE_URL=jdbc:postgresql://192.168.1.55:30091/db_name I have a shell script

#/bin/bash

read -p "Please enter the Database IP:" DATABASE_IP
read -p "Please enter the Database Port:" PORT
echo $DATABASE_IP $PORT
sed -i "s/${DATABASE_IP}" ~/.env

I am not familiar with the string manipulation. How can I complete the shell script to update a .env file

2
  • The sed command s/// substitutes one value by another one. I don't see a replacement value in your command. Commented Mar 23, 2023 at 8:46
  • Have a look at envsubst? Perhaps it is exactly what you need, and easier to use. The idea would be that you create a template environment file, .env_template, where you use a variable for the IP address jdbc:postgresql://$DATABASE_IP:30091/db_name, and then use envsubst to create from this the actual .env file. Commented Mar 23, 2023 at 8:50

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.