Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On Unix, PowerShell should define the SHELL environment variable on startup #12150

Open
mklement0 opened this issue Mar 18, 2020 · 2 comments
Open

Comments

@mklement0
Copy link
Contributor

@mklement0 mklement0 commented Mar 18, 2020

POSIX-like shells such as bash define the SHELL environment variable on startup as the full path of the current user's default shell (e.g., /bin/bash). (They do so even if they're not the default shell themselves - unless the variable is already defined.)

This variable is mandated by POSIX:

SHELL
This variable shall represent a pathname of the user's preferred command language interpreter.

If PowerShell itself functions as the default shell, SHELL is never set, because PowerShell doesn't set it.

Unix utilities may rely on the presence of this environment variable.

Therefore, PowerShell, like POSIX-like shells, should define SHELL on startup, unless it is already defined.

Environment data

Written as of:

PowerShell 7.0
@iSazonov

This comment has been minimized.

Copy link
Collaborator

@iSazonov iSazonov commented Mar 19, 2020

Unix utilities may rely on the presence of this environment variable.

Interesting, how would we test that defining this variable will have the desired effects and do not break these utilities?

@mklement0

This comment has been minimized.

Copy link
Contributor Author

@mklement0 mklement0 commented Mar 19, 2020

how would we test

I don't think you can, but I don't think we have to:

Even non-POSIX shells such as csh set the SHELL variable, and even the behavioral variations among POSIX-like shells (except if they're in compatibility mode) mean that you can't make blind assumptions about how, specifically, to invoke the shell reported by SHELL (other than without arguments).

In other words: no existing utility can make fixed assumptions about specific behaviors exhibited by the user's default shell, as reflected in SHELL.

However, knowing what shell is the user's default shell is important information, which PowerShell should provide too.

An important use case is that installer utilities may decide what shell-specific initialization files (profiles) they need to modify and how.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.