Skip to content

Switch-Process (exec) fails to make the replacement process inherit the calling process' environment variables #18432

@mklement0

Description

@mklement0

Prerequisites

Steps to reproduce

It is understood that the newly introduced, Unix-only Switch-Process cmdlet (alias exec) is not designed to have full feature parity with the exec built-in in POSIX-compatible shells, notably not with respect to supporting stream redirections.

However, making the replacement process inherit the caller's environment is an important part of exec functionality (and it is how it works in POSIX-compatible shells).

Related discussion predating Switch-Process:

# Run on macOS or Linux.
# Note the use of `exec`; if you remove it, 'bar' prints as expected
pwsh -nop -c '$env:FOO=''bar''; exec /bin/sh -c ''echo $FOO'''

Expected behavior

bar

Actual behavior

(no output)

Error details

No response

Environment data

PowerShell Core 7.3.0-rc.1 on Unix-like platforms

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions