Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
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
17 changes: 13 additions & 4 deletions 17 src/System.Management.Automation/engine/InitialSessionState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4072,6 +4072,15 @@ internal static string GetClearHostFunctionText()
}
}

#if UNIX
internal static string GetExecFunctionText()
{
return @"
Switch-Process -WithCommand $args
";
}
#endif

/// <summary>
/// This is the default function to use for man/help. It uses
/// splatting to pass in the parameters.
Expand Down Expand Up @@ -4677,10 +4686,6 @@ internal static SessionStateAliasEntry[] BuiltInAliases
new SessionStateAliasEntry("sls", "Select-String"),
};

#if UNIX
builtInAliases.Add(new SessionStateAliasEntry("exec", "Switch-Process"));
#endif

return builtInAliases.ToArray();
}
}
Expand Down Expand Up @@ -4709,6 +4714,10 @@ internal static SessionStateAliasEntry[] BuiltInAliases
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("help", GetHelpPagingFunctionText(), isProductCode: true, languageMode: systemLanguageMode),
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("prompt", DefaultPromptFunctionText, isProductCode: true, languageMode: systemLanguageMode),

#if UNIX
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("exec", GetExecFunctionText(), isProductCode: true, languageMode: systemLanguageMode),
#endif

// Functions that require full language mode and are trusted
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("Clear-Host", GetClearHostFunctionText(), isProductCode: true, languageMode: PSLanguageMode.FullLanguage),
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("TabExpansion2", s_tabExpansionFunctionText, isProductCode: true, languageMode: PSLanguageMode.FullLanguage),
Expand Down
13 changes: 9 additions & 4 deletions 13 test/powershell/Modules/Microsoft.PowerShell.Core/Exec.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ Describe 'Switch-Process tests for Unix' -Tags 'CI' {
$global:PSDefaultParameterValues = $originalDefaultParameterValues
}

It 'Exec alias should map to Switch-Process' {
$alias = Get-Command exec
$alias | Should -BeOfType [System.Management.Automation.AliasInfo]
$alias.Definition | Should -BeExactly 'Switch-Process'
It 'Exec function should map to Switch-Process' {
$func = Get-Command exec
$func | Should -BeOfType [System.Management.Automation.CommandInfo]
$func.Definition | Should -Not -BeNullOrEmpty
}

It 'Exec by itself does nothing' {
Expand Down Expand Up @@ -53,6 +53,11 @@ Describe 'Switch-Process tests for Unix' -Tags 'CI' {
$env = pwsh -noprofile -outputformat text -command { $env:TEST_FOO='my test = value'; Switch-Process bash -c 'echo $TEST_FOO' }
$env | Should -BeExactly 'my test = value'
}

It 'The command can include a -w parameter' {
$out = pwsh -noprofile -outputformat text -command { exec /bin/echo 1 -w 2 }
$out | Should -BeExactly '1 -w 2'
}
}

Describe 'Switch-Process for Windows' -Tag 'CI' {
Expand Down
1 change: 0 additions & 1 deletion 1 test/powershell/engine/Basic/DefaultCommands.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ Describe "Verify approved aliases list" -Tags "CI" {
"Alias", "epsn", "Export-PSSession", $($FullCLR ), "", "", ""
"Alias", "erase", "Remove-Item", $($FullCLR -or $CoreWindows -or $CoreUnix), "", "", ""
"Alias", "etsn", "Enter-PSSession", $($FullCLR -or $CoreWindows -or $CoreUnix), "", "", ""
"Alias", "exec", "Switch-Process", $( $CoreUnix), "", "", ""
"Alias", "exsn", "Exit-PSSession", $($FullCLR -or $CoreWindows -or $CoreUnix), "", "", ""
"Alias", "fc", "Format-Custom", $($FullCLR -or $CoreWindows -or $CoreUnix), "ReadOnly", "", ""
"Alias", "fhx", "Format-Hex", $($FullCLR -or $CoreWindows -or $CoreUnix), "", "", ""
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.