Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting double quotes in values in env file #212

Open
HimanshuJha2000 opened this issue Jun 6, 2023 · 2 comments
Open

Getting double quotes in values in env file #212

HimanshuJha2000 opened this issue Jun 6, 2023 · 2 comments

Comments

@HimanshuJha2000
Copy link

HimanshuJha2000 commented Jun 6, 2023

We have a usecase where we let user give their environment variables which we write to a env file using this package, that file will be sent to docker as an env file. While seeing the logs, I observe that I'm getting double quotes over values of env variables due to which the script which I mounted on my docker I've to assume that double quotes have been added to the values of env variables there as well . On debugging through this package, saw this line

for k, v := range envMap {
		if d, err := strconv.Atoi(v); err == nil {
			lines = append(lines, fmt.Sprintf(`%s=%d`, k, d))
		} else {
			lines = append(lines, fmt.Sprintf(`%s="%s"`, k, doubleQuoteEscape(v)))
		}
	}

Where we're adding double quotes over the values in map while appending to the file. Not sure if it's a bug or is being done in this way for some purpose. As of now I move to a different package but want to move back to this package only. Can you please help me with this?

@HimanshuJha2000 HimanshuJha2000 changed the title Double quotes in values .env Getting double quotes in values in env file Jun 6, 2023
@fakeyanss
Copy link

The same problem I have.

I want to set env_A="abc", and env_B="${env_A}_123".

But godotenv gives me env_B="${env_A}_123", the variable syntax is not compatible.

Code like:

envMap, _ := godotenv.Read("some_file")
envMap["env_A"] = "abc"
_ = godotenv.Write(envMap, d.envFile)

envMap["env_B"] = "${env_A}_123"
_ = godotenv.Write(envMap, d.envFile)

and run cat some_file shows:

env_A="abc"
env_B="\${env_A}_123"

@fakeyanss
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants