Fix powershell to update the PATH environment variable only if PATH exists (#5021)

This commit is contained in:
Steve Lee 2017-10-05 14:23:52 -07:00 committed by Dongbo Wang
parent 87b34fe8cb
commit ba7dfcc0d0
2 changed files with 11 additions and 4 deletions

View File

@ -136,10 +136,13 @@ namespace Microsoft.PowerShell
// put PSHOME in front of PATH so that calling `powershell` within `powershell` always starts the same running version
string path = Environment.GetEnvironmentVariable("PATH");
string pshome = Utils.DefaultPowerShellAppBase;
if (!path.Contains(pshome))
if (path != null)
{
Environment.SetEnvironmentVariable("PATH", pshome + Path.PathSeparator + path);
string pshome = Utils.DefaultPowerShellAppBase;
if (!path.Contains(pshome))
{
Environment.SetEnvironmentVariable("PATH", pshome + Path.PathSeparator + path);
}
}
try

View File

@ -238,7 +238,7 @@ Describe "ConsoleHost unit tests" -tags "Feature" {
$observed | Should Be $BoolValue
}
It "-File should return exit code from script" -TestCases @(
It "-File '<filename>' should return exit code from script" -TestCases @(
@{Filename = "test.ps1"},
@{Filename = "test"}
) {
@ -490,6 +490,10 @@ foo
It "`$PSHOME should be in front so that powershell.exe starts current running PowerShell" {
powershell -v | Should Match $psversiontable.GitCommitId
}
It "powershell starts if PATH is not set" -Skip:($IsWindows) {
bash -c "unset PATH;$powershell -c '1+1'" | Should BeExactly 2
}
}
Context "Ambiguous arguments" {