综合技术

Pipeline and chain operators (|| and and&) now in pwsh

微信扫一扫,分享到朋友圈

Pipeline and chain operators (|| and and&) now in pwsh

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

微信推视频号:开启内测,入口在朋友圈下方

上一篇

微信推视频号:开启内测 入口在朋友圈下方

下一篇

你也可能喜欢

评论已经被关闭。

插入图片

热门栏目

Pipeline and chain operators (|| and and&) now in pwsh

长按储存图像,分享给朋友