Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to copy text to local .env file with bash

Is there a way in a shell script to copy text into a local .env file so that I can automate setting those environment variables?

example, I want to copy this to an .env file that sits in the same directory I’m already cd’d to

PIN=1
DEVICE_PREFIX=xxx
DEV=true

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

#!/bin/bash

text=$(cat << EOF
PIN=1
DEVICE_PREFIX=xxx
DEV=true
EOF
)

# Specify the path to the .env file
env_file=".env"

# Copy the text to the .env file
echo "$text" > "$env_file"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading