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

Mention the quasi-interactive, REPL-like behavior of -File - and -Command - and a workaround #11098

Open
mklement0 opened this issue May 10, 2024 · 0 comments
Assignees
Labels
area-about Area - About_ topics

Comments

@mklement0
Copy link
Contributor

mklement0 commented May 10, 2024

Type of issue

Missing information

Feedback

It is reasonable for users - especially those familiar with POSIX-compatible shells such as Bash - to expect -File - to treat its stdin input as a whole as if it were the content of a script file.
-Command - does not have a POSIX-compatible shell counterpart, but the expectation applies analogously.

Unfortunately, both -File - and -Command - exhibit quasi-interactive behavior that seems to be geared toward supporting REPL-like functionality via stdin: see PowerShell/PowerShell#21808 (comment) for a summary.

To get the expected behavior, the following workaround is currently required, which is worth mentioning:

  • Enclose the code in & { ... }

  • Ensure that it is terminated by two trailing newlines.

Example:

  • From PowerShell:
@'
& { 
  Get-Date
  $PROFILE
}

'@ |
  pwsh -NoProfile -Command -
  • From Bash:
pwsh -NoProfile -Command - <<'EOF'
& { 
  Get-Date
  $PROFILE
}

EOF

Note that, without the extra newline (empty line), both commands above currently provide no output, which is a bug discussed in:

Page URL

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_Pwsh?view=powershell-7.4

Content source URL

https://github.com/MicrosoftDocs/PowerShell-Docs/blob/main/reference/7.4/Microsoft.PowerShell.Core/About/about_Pwsh.md

Author

@sdwheeler

Document Id

4ccd2aa8-1a49-5b9d-04ee-5d2c61fb3c38

@mklement0 mklement0 added the needs-triage Waiting - Needs triage label May 10, 2024
@mklement0 mklement0 changed the title Mention the quasi-interactive, REPL-like behavior of -File - and -Command - Mention the quasi-interactive, REPL-like behavior of -File - and -Command - and a workaround May 10, 2024
@sdwheeler sdwheeler self-assigned this May 13, 2024
@sdwheeler sdwheeler added area-about Area - About_ topics and removed needs-triage Waiting - Needs triage labels May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-about Area - About_ topics
Projects
None yet
Development

No branches or pull requests

2 participants