Fix powershell to update the PATH environment variable only if PATH exists (#5021)
This commit is contained in:
parent
87b34fe8cb
commit
ba7dfcc0d0
@ -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
|
||||
|
@ -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" {
|
||||
|
Loading…
Reference in New Issue
Block a user