Skip to content

Pipeline chain operators - #9849

Merged
Dongbo Wang (daxian-dbw) merged 42 commits into
PowerShell:masterfrom
rjmholt:bash-operators
Oct 17, 2019
Merged

Dongbo Wang (daxian-dbw) merged 42 commits into
PowerShell:masterfrom
rjmholt:bash-operators

Conversation

@rjmholt

@rjmholt Rob Holt (rjmholt) commented Jun 7, 2019 •

Copy link
Copy Markdown
Collaborator

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

Comment thread src/System.Management.Automation/engine/parser/AstVisitor.cs Outdated
@daxian-dbw

Dongbo Wang (daxian-dbw) commented Jun 11, 2019 •

Copy link
Copy Markdown
Member

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

@rjmholt

Copy link
Copy Markdown
Collaborator Author

Discussed this offline with Dongbo Wang (@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
Copy Markdown

Rob Holt (@rjmholt) Can you explain the reasoning in this PR thread?

@rjmholt

Copy link
Copy Markdown
Collaborator Author

Can you explain the reasoning in this PR thread?

I've discussed again with Dongbo Wang (@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
Copy Markdown
Collaborator Author

Please see PowerShell/PowerShell-RFC#192

@stereokai

Copy link
Copy Markdown

Excellent, thanks

Comment thread build.psm1
Comment thread build.psm1
Comment thread build.psm1
@daxian-dbw
Dongbo Wang (daxian-dbw) merged commit 2a518fc into PowerShell:master Oct 17, 2019
@daxian-dbw Dongbo Wang (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
@rjmholt

Copy link
Copy Markdown
Collaborator Author

🎉

@rjmholt Rob Holt (rjmholt) mentioned this pull request Oct 17, 2019
8 of 14 tasks

Copy link
Copy Markdown
Member

🎉🎉🎉 Nice!

@Graham-Beer

Copy link
Copy Markdown

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

@anmenaga Andrew (anmenaga) changed the title Pipeline chain operators (&&, ||) Pipeline chain operators Oct 22, 2019
Ben Boeckel (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.
Ben Boeckel (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.
Ryan Yates (kilasuit) pushed a commit to kilasuit/PowerShell that referenced this pull request Nov 9, 2019
bb010g (bb010g) added a commit to bb010g/dein.vim that referenced this pull request Dec 6, 2019
bb010g (bb010g) added a commit to bb010g/dein.vim that referenced this pull request Dec 6, 2019
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
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