Score:2

How to create .env multiline variable

id flag

The title may be a bit confusing, so a little explanation. I need to configure an application by passing a PKCS1 PEM encoded key using environment variable. The App is configured using a .env file

Locally I just export MY_ENV_VAR=$(cat my_key.pem), but on the server, it needs to be inside the .env file and needs to contain the value, not a command.

I've tried

echo MY_ENV_VAR=`awk 'NF {sub(/\n/, ""); printf "%s\\n",$0;}' my_key.pem` >> .env

But the generated string was not accepted by the application I'm trying to set up, it complains that the key is not PKCS1/8 compliant.

For now, I've added the export MY_ENV_VAR=$(cat my_key.pem) to my .profile and I launch it manually, but I would prefer to just keep the config in the .env.

How can I do this? I'm currently running GNU bash, version 5.0.17(1)-release (x86_64-pc-linux-gnu) but I am fine to switch to other shell if needs be.

Appleoddity avatar
ng flag
Wrap it in single quotes. See https://stackoverflow.com/questions/49457787/how-to-export-a-multi-line-environment-variable-in-bash-terminal-e-g-rsa-privat
Krystian avatar
id flag
unfortunately this does not work in my case.
Bat0u89 avatar
ky flag
you have to open the first quote and press enter, it'll go to the next line, when you add the closing quote and press enter it'll assign the value
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.