2

I'm trying to compose up a docker-compose file and there is one step where I ran grep -v '^#' .env to get all the uncommented lines from .env file to set environment variables.

In the .env file, it looks like this

DB_ENGINE=django.db.backends.postgresql

However, after running grep -v '^#' .env and I check the environment, variable DB_ENGINE has value of "django.db.backends.postgresql\r" (notice the trailing \r there).

How can I overcome this? I've been doing this for a long time and it has never happened before.

knl
  • 969
  • 11
  • 35
  • 2
    One of your files probably has DOS/Windows-style line endings. See [this question](https://stackoverflow.com/questions/39527571/are-shell-scripts-sensitive-to-encoding-and-line-endings), and especially the "Solutions" section of the top answer. – Gordon Davisson Jul 28 '20 at 05:08

1 Answers1

1

Without trying a dos2unix on all your files, you could simply remove any \r from your grep result, as in here, with:

grep -v '^#' .env| tr -d '\r'
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250