10BC0 Pipeline chain operators by rjmholt · Pull Request #9849 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@rjmholt
Copy link
Collaborator
@rjmholt rjmholt commented Jun 7, 2019

This PR is specified by PowerShell/PowerShell-RFC#192

PR Summary

Resolves #3241.

Implements && and ||.

A statement like cmd1 && cmd2 should behave like cmd1; if ($?) { cmd2 }.

After discussion with the @PowerShell/powershell-committee, this feature has the following charateristics:

  • cmd1 && cmd2 behaves like cmd1; if ($?) { cmd2 }
  • cmd1 || cmd2 behaves like cmd1; if (-not $?) { cmd2 }
  • cmd1 && cmd2 && cmd3 is left associative: [cmd1 && cmd2] && cmd3
  • No control flow statements in pipeline chains; only pipelines. Control flow statements are still possible with subexpressions in pipelines (cmd1 && $(break)). These were taken out due to the inconsitencies they posed at a grammatical, data structure and semantic level.
  • Assignment is consistent with other assignment in PowerShell, so that a script terminating error will not result in a partial assignment, but a pipeline-terminating error will.
  • This syntax is available as the PSPipelineChainOperators experimental feature

PR Checklist

@rjmholt rjmholt requested review from SteveL-MSFT and daxian-dbw June 7, 2019 01:11
SeeminglyScience
SeeminglyScience reviewed < 8000 span class="color-fg-muted"> Jun 7, 2019
@daxian-dbw
Copy link
Member
daxian-dbw commented Jun 11, 2019

The && and || operators allow statements for both operands in bash. Why don't we do the same in PowerShell?

@rjmholt
Copy link
Collaborator Author
rjmholt commented Jun 11, 2019

Discussed this offline with @daxian-dbw. We've decided to get rid of the subordinate statements and move assignment up to the whole chain (so no $x = cmd1 && $y = cmd2). I'll try to rework this today or tomorrow

@stereokai
Copy link

@rjmholt Can you explain the reasoning in this PR thread?

@rjmholt
Copy link
Collaborator Author
rjmholt commented Jun 12, 2019

Can you explain the reasoning in this PR thread?

I've discussed again with @daxian-dbw and we agreed this is now best served by an RFC. When that RFC is accepted, I'll make the desired changes in this branch

@rjmholt
Copy link
Collaborator Author
rjmholt commented Jun 12, 2019

Please see PowerShell/PowerShell-RFC#192

@stereokai
Copy link

Excellent, thanks

@daxian-dbw daxian-dbw merged commit 2a518fc into PowerShell:master Oct 17, 2019
@daxian-dbw daxian-dbw added the CL-Engine Indicates that a PR should be marked as an engine change in the Change Log label Oct 17, 2019
@daxian-dbw daxian-dbw added this to the 7.0.0-preview.5 milestone Oct 17, 2019
@rjmholt
Copy link
Collaborator Author
rjmholt commented Oct 17, 2019

🎉

@rjmholt rjmholt mentioned this pull request Oct 17, 2019
14 tasks
Copy link
Member

🎉🎉🎉 Nice!

@Graham-Beer
Copy link

This is awesome! Looking forward to having a look in PS7 preview 5!

@anmenaga anmenaga changed the title Pipeline chain operators (&&, ||) Pipeline chain operators Oct 22, 2019
mathstuf added a commit to mathstuf/tar-rs that referenced this pull request Oct 26, 2019
The `&&` syntax is not supported in PowerShell. See
PowerShell/PowerShell#9849.
mathstuf added a commit to mathstuf/tar-rs that referenced this pull request Oct 26, 2019
The `&&` syntax is not supported in PowerShell (yet). See
PowerShell/PowerShell#9849.
kilasuit pushed a commit to kilasuit/PowerShell that referenced this pull request Nov 9, 2019
bb010g added a commit to bb010g/dein.vim that referenced this pull request Dec 6, 2019
bb010g added a commit to bb010g/dein.vim that referenced this pull request Dec 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-Engine Indicates that a PR should be marked as an engine change in the Change Log

Projects

None yet
0