Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,13 @@ internal static int Start(

// 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
Expand Down
6 changes: 5 additions & 1 deletion test/powershell/Host/ConsoleHost.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
) {
Expand Down Expand Up @@ -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" {
Expand Down