-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Environment.ExpandEnvironmentVariables on Linux has Windows behavior #25792
Comments
My guess is this was done intentionally -- so existing code passing %VAR_NAME% "just works" when used on Unix. For code written for Unix, it is certainly unexpected. public string Environment.ExpandEnvironmentVariables(string name, EnvironmentVariablesExpandFlavor flavor = EnvironmentVariablesExpandFlavor.PlatformDefault);
[Flags]
public enum EnvironmentVariablesExpandFlavor
{
PlatformDefault = 0x1,
PercentSigns = 0x2,
DollarSigns = 0x4
} with better names... Maybe @stephentoub recalls context. |
Mainly because that's how it's documented:
I could be convinced that you'd never do that on unix and this is really just surfacing a Windows-ism and so we should use $ on unix instead of %. But we'd want to understand how badly breaking that would be. I'd be worried that code has already done |
I think we should add a new overload that supports this.
ps - string.Replace('$', '%') would add $ suffixes to your expanded env vars 😉 |
For cross-platform development both variants should be allowed, similar to the path-separator ( Batch allows the Further there wouldn't be any breaking changes, since |
Except $var on Windows may start to be reinterpreted, changing output in some cases. |
It may also be worth considering expanding |
Maybe a whole new API should be used for this because Personally I would prefer something like |
Maybe I am misunderstanding the complexity of |
Because it is not path specific. Environment variables can be anything. Not only paths.
This would certainly be a breaking change for any code that already relies on the %VAR% pattern. |
Is there any progress for this feature. |
@moh-hassan no proposal has been made for this. |
Environment.ExpandEnvironmentVariables()
on Linux expands variables in%VAR_NAME%
format rather than$VAR_NAME
.SDK version: 2.1.4
OS: Ubuntu 16.04
A simple test:
Expected value:
/home/{user}/test
Actual value:
$HOME/test
However running:
gives expanded result
/home/{user}/test
.The text was updated successfully, but these errors were encountered: