2

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.

Krystian
  • 306
  • 1
  • 6
  • 19
  • 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 – Appleoddity Oct 14 '22 at 03:55
  • unfortunately this does not work in my case. – Krystian Oct 18 '22 at 11:57
  • 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 – Bat0u89 Jun 16 '23 at 19:01

0 Answers0