-
Notifications
You must be signed in to change notification settings - Fork 830
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
bug: 0.16 doesn't pass current shell environment variables to command #1876
Comments
After some digging it appeared that is was just when the environment variable value has additional The culprit is likely in
This seems to fix it for me. But i'm not sure of the implications of this change: // SliceToMap converts an env map to env slice suitable for syscall.Exec
func SliceToMap(env []string) map[string]string {
envMap := map[string]string{}
for _, envVar := range env {
varValue := strings.Split(envVar, "=")
if len(varValue) >= 2 {
envMap[varValue[0]] = strings.Join(varValue[1:], "=")
}
}
return envMap
} |
Hi @garry-harthill-cko , thanks for the additional info! I was testing this myself and confirmed again that env vars in general do work:
But as you've identified the env var will not be set if the value of it contains
And of course it gets traced back to my custom env var parsing code that I wrote so I could work with env vars as a map rather than a slice. I'll get this fixed and get a patch release out this week. I might try to find a library that does this as I imagine with env vars and quoting issues there may be other bugs lurking in this function. |
The old code did not allow the equals sign in the environment variable value. But the equals sign is a valid character in value. Fixes #1876
@garry-harthill-cko I believe I've fixed this in #1879 just now. Would you be able to build latest master and see if the issue is fixed for you? |
Thanks @Stratus3D |
Yes, today or tomorrow hopefully. A fix for #1860 also needs to be included. |
Thank you for this great tool |
Yes this fixes it. Thanks! |
Awesome! Thank you for confirming. I plan to release the patch in version 0.16.1 tonight. |
@Stratus3D thank you for your work.
I thought it would fit with this issue. |
I am also seeing variables ending in '=" are excluded (again?) and this is very common with base64 credentials:
|
Hi @duckworth. Thanks for reporting. I believe my PR here fixes that - #1977. Can you test it when you get a chance? @NickNeck interesting. I'm not even sure Go's |
Yes, I just tried #1977 locally and it fixes environment variables with equals sign in value issue. |
It works with the main branch. Thank you.
|
Describe the Bug
Shells environment variables aren't set in the context of the command that
asdf
execsSteps to Reproduce
Set an environment variable that the command requires
Run the command
Application displays an error about missing environment variable
Expected Behaviour
I would expect the parent shell environment to be passed to the exec'd binary.
Actual Behaviour
The command doesn't recognise environment variables.
However manually running
asdf env terraform echo $SOME_ENVAR
does actually show the contents of the variable.Environment
OS: Darwin MAC-G6WN34MH7H 23.6.0 Darwin Kernel Version 23.6.0: Fri Nov 15 15:13:15 PST 2024; root:xnu-10063.141.1.702.7~1/RELEASE_ARM64_T6000 arm64 SHELL: zsh 5.9 (x86_64-apple-darwin23.0) BASH VERSION: 5.2.37(1)-release ASDF VERSION: v0.16.0 ASDF INTERNAL VARIABLES: ASDF_DEFAULT_TOOL_VERSIONS_FILENAME=.tool-versions ASDF_DATA_DIR=/Users/user/.asdf ASDF_CONFIG_FILE=/Users/user/.asdfrc ASDF INSTALLED PLUGINS: terraform https://github.com/asdf-community/asdf-hashicorp.git c44c314b220f36790bbee4f6869e16a95ac36bfc
asdf plugins affected (if relevant)
No response
The text was updated successfully, but these errors were encountered: