I’m probably missing something here but I’m trying to save environment variables with newlines into a .env file. Ideally I want to do this with all available env variables (output of env).
Take this variable:
export MY_VAR="Line 1
Line 2
Line 3"
How do I save this in a .env file that would look like:
variables.env
MY_VAR=Line 1nLine2nLine3
And how can I do this with all available env variables, like from env
? I tried this:
while IFS= read -r -d '' line; do
line=$(echo -n "$line" | sed '$!s/$/\n/' | tr -d 'n')
echo "$line" >> variables.env
done < <(env -0)
New contributor
gitstackyflow is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.