Skip to content

Document pipeline chain operators (&&/||) #4856

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

Merged
merged 9 commits into from
Oct 18, 2019

Conversation

rjmholt
Copy link
Contributor

@rjmholt rjmholt commented Sep 30, 2019

Resolves #4853.

Document pipeline chain operators (&&/||), which are added to PowerShell 7 by PowerShell/PowerShell#9849.

See also: PowerShell/PowerShell-RFC#192.

Version(s) of document impacted

  • Impacts 7 document
  • Impacts 6 document
  • Impacts 5.1 document
  • Impacts 5.0 document
  • Impacts 4.0 document
  • Impacts 3.0 document

Reason(s) for not updating all version of documents

  • The documented feature was introduced in version (list version here) of PowerShell
  • This issue only shows up in version (list version(s) here) of the document
  • This PR partially fixes the issue, and issue # tracks the remaining work

@opbld30
Copy link

opbld30 commented Sep 30, 2019

Docs Build status updates of commit 2f31955:

⚠️ Validation status: warnings

File Status Preview URL Details
reference/7/Microsoft.PowerShell.Core/About/about_Operators.md ⚠️Warning View (powershell-7) Details
reference/7/Microsoft.PowerShell.Core/About/about_Pipeline_Chain_Operators.md ⚠️Warning View (powershell-7) Details

reference/7/Microsoft.PowerShell.Core/About/about_Operators.md

  • [Warning] Metadata with following name(s) are not allowed to be set in Yaml header, or as file level metadata in docfx.json, or as global metadata in docfx.json: locale. They are generated by Docs platform, so the values set in these 3 places will be ignored. Please remove them from all 3 places to resolve the warning.

reference/7/Microsoft.PowerShell.Core/About/about_Pipeline_Chain_Operators.md

  • [Warning] Metadata with following name(s) are not allowed to be set in Yaml header, or as file level metadata in docfx.json, or as global metadata in docfx.json: locale. They are generated by Docs platform, so the values set in these 3 places will be ignored. Please remove them from all 3 places to resolve the warning.

For more details, please refer to the build report.

Note: If you changed an existing file name or deleted a file, broken links in other files to the deleted or renamed file are listed only in the full build report.

@sdwheeler sdwheeler added this to the 7.0.0 milestone Sep 30, 2019
@opbld31
Copy link

opbld31 commented Sep 30, 2019

Docs Build status updates of commit 741e1af:

⚠️ Validation status: warnings

File Status Preview URL Details
reference/7/Microsoft.PowerShell.Core/About/about_Operators.md ⚠️Warning View (powershell-7) Details
reference/7/Microsoft.PowerShell.Core/About/about_Pipeline_Chain_Operators.md ⚠️Warning View (powershell-7) Details

reference/7/Microsoft.PowerShell.Core/About/about_Operators.md

  • [Warning] Metadata with following name(s) are not allowed to be set in Yaml header, or as file level metadata in docfx.json, or as global metadata in docfx.json: locale. They are generated by Docs platform, so the values set in these 3 places will be ignored. Please remove them from all 3 places to resolve the warning.

reference/7/Microsoft.PowerShell.Core/About/about_Pipeline_Chain_Operators.md

  • [Warning] Metadata with following name(s) are not allowed to be set in Yaml header, or as file level metadata in docfx.json, or as global metadata in docfx.json: locale. They are generated by Docs platform, so the values set in these 3 places will be ignored. Please remove them from all 3 places to resolve the warning.

For more details, please refer to the build report.

Note: If you changed an existing file name or deleted a file, broken links in other files to the deleted or renamed file are listed only in the full build report.

@opbld32
Copy link

opbld32 commented Sep 30, 2019

Docs Build status updates of commit 118a564:

⚠️ Validation status: warnings

File Status Preview URL Details
reference/7/Microsoft.PowerShell.Core/About/about_Operators.md ⚠️Warning View (powershell-7) Details
reference/7/Microsoft.PowerShell.Core/About/about_Pipeline_Chain_Operators.md ⚠️Warning View (powershell-7) Details

reference/7/Microsoft.PowerShell.Core/About/about_Operators.md

  • [Warning] Metadata with following name(s) are not allowed to be set in Yaml header, or as file level metadata in docfx.json, or as global metadata in docfx.json: locale. They are generated by Docs platform, so the values set in these 3 places will be ignored. Please remove them from all 3 places to resolve the warning.

reference/7/Microsoft.PowerShell.Core/About/about_Pipeline_Chain_Operators.md

  • [Warning] Metadata with following name(s) are not allowed to be set in Yaml header, or as file level metadata in docfx.json, or as global metadata in docfx.json: locale. They are generated by Docs platform, so the values set in these 3 places will be ignored. Please remove them from all 3 places to resolve the warning.

For more details, please refer to the build report.

Note: If you changed an existing file name or deleted a file, broken links in other files to the deleted or renamed file are listed only in the full build report.

@opbld34
Copy link

opbld34 commented Sep 30, 2019

Docs Build status updates of commit 3c5eb02:

⚠️ Validation status: warnings

File Status Preview URL Details
reference/7/Microsoft.PowerShell.Core/About/about_Operators.md ⚠️Warning View (powershell-7) Details
reference/7/Microsoft.PowerShell.Core/About/about_Pipeline_Chain_Operators.md ⚠️Warning View (powershell-7) Details

reference/7/Microsoft.PowerShell.Core/About/about_Operators.md

  • [Warning] Metadata with following name(s) are not allowed to be set in Yaml header, or as file level metadata in docfx.json, or as global metadata in docfx.json: locale. They are generated by Docs platform, so the values set in these 3 places will be ignored. Please remove them from all 3 places to resolve the warning.

reference/7/Microsoft.PowerShell.Core/About/about_Pipeline_Chain_Operators.md

  • [Warning] Metadata with following name(s) are not allowed to be set in Yaml header, or as file level metadata in docfx.json, or as global metadata in docfx.json: locale. They are generated by Docs platform, so the values set in these 3 places will be ignored. Please remove them from all 3 places to resolve the warning.

For more details, please refer to the build report.

Note: If you changed an existing file name or deleted a file, broken links in other files to the deleted or renamed file are listed only in the full build report.

succeeded. Conversely, the `||` operator executes the right-hand pipeline if
the left-hand pipeline failed.

This can be use for conditional execution of software deployments. For example:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use -> used.

The language here feels too specific for an operator to me.

If this example demands language like that, we should change the example.

I want to be able to emphasise that this works with native commands based on $?/$LASTEXITCODE and not just with cmdlets/functions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

In this example the `npm run deploy` command only runs if the build command
succeeds.

> [!NOTE]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would put this note immediately under the Long Description

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved

@opbld33
Copy link

opbld33 commented Oct 1, 2019

Docs Build status updates of commit ab5ef75:

⚠️ Validation status: warnings

File Status Preview URL Details
reference/7/Microsoft.PowerShell.Core/About/about_Operators.md ⚠️Warning View (powershell-7) Details
reference/7/Microsoft.PowerShell.Core/About/about_Pipeline_Chain_Operators.md ⚠️Warning View (powershell-7) Details

reference/7/Microsoft.PowerShell.Core/About/about_Operators.md

  • [Warning] Metadata with following name(s) are not allowed to be set in Yaml header, or as file level metadata in docfx.json, or as global metadata in docfx.json: locale. They are generated by Docs platform, so the values set in these 3 places will be ignored. Please remove them from all 3 places to resolve the warning.

reference/7/Microsoft.PowerShell.Core/About/about_Pipeline_Chain_Operators.md

  • [Warning] Metadata with following name(s) are not allowed to be set in Yaml header, or as file level metadata in docfx.json, or as global metadata in docfx.json: locale. They are generated by Docs platform, so the values set in these 3 places will be ignored. Please remove them from all 3 places to resolve the warning.

For more details, please refer to the build report.

Note: If you changed an existing file name or deleted a file, broken links in other files to the deleted or renamed file are listed only in the full build report.

@opbld31
Copy link

opbld31 commented Oct 1, 2019

Docs Build status updates of commit 9bbf66a:

⚠️ Validation status: warnings

File Status Preview URL Details
reference/7/Microsoft.PowerShell.Core/About/about_Operators.md ⚠️Warning View (powershell-7) Details
reference/7/Microsoft.PowerShell.Core/About/about_Pipeline_Chain_Operators.md ⚠️Warning View (powershell-7) Details

reference/7/Microsoft.PowerShell.Core/About/about_Operators.md

  • [Warning] Metadata with following name(s) are not allowed to be set in Yaml header, or as file level metadata in docfx.json, or as global metadata in docfx.json: locale. They are generated by Docs platform, so the values set in these 3 places will be ignored. Please remove them from all 3 places to resolve the warning.

reference/7/Microsoft.PowerShell.Core/About/about_Pipeline_Chain_Operators.md

  • [Warning] Metadata with following name(s) are not allowed to be set in Yaml header, or as file level metadata in docfx.json, or as global metadata in docfx.json: locale. They are generated by Docs platform, so the values set in these 3 places will be ignored. Please remove them from all 3 places to resolve the warning.

For more details, please refer to the build report.

Note: If you changed an existing file name or deleted a file, broken links in other files to the deleted or renamed file are listed only in the full build report.

@sdwheeler sdwheeler force-pushed the pipeline-chain-operators branch from 9bbf66a to 211ba99 Compare October 1, 2019 16:35
@opbld32
Copy link

opbld32 commented Oct 1, 2019

Docs Build status updates of commit 211ba99:

⚠️ Validation status: warnings

File Status Preview URL Details
reference/7/Microsoft.PowerShell.Core/About/about_Operators.md ⚠️Warning View (powershell-7) Details
reference/7/Microsoft.PowerShell.Core/About/about_Pipeline_Chain_Operators.md ⚠️Warning View (powershell-7) Details

reference/7/Microsoft.PowerShell.Core/About/about_Operators.md

  • [Warning] Metadata with following name(s) are not allowed to be set in Yaml header, or as file level metadata in docfx.json, or as global metadata in docfx.json: locale. They are generated by Docs platform, so the values set in these 3 places will be ignored. Please remove them from all 3 places to resolve the warning.

reference/7/Microsoft.PowerShell.Core/About/about_Pipeline_Chain_Operators.md

  • [Warning] Metadata with following name(s) are not allowed to be set in Yaml header, or as file level metadata in docfx.json, or as global metadata in docfx.json: locale. They are generated by Docs platform, so the values set in these 3 places will be ignored. Please remove them from all 3 places to resolve the warning.

For more details, please refer to the build report.

Note: If you changed an existing file name or deleted a file, broken links in other files to the deleted or renamed file are listed only in the full build report.

@sdwheeler sdwheeler added the hold-for-pr Waiting - for PR merge label Oct 1, 2019

These operators use the `$?` and `$LASTEXITCODE` variables to determine if a
pipeline failed. This allows you to use them with native command and not just
with cmdlets or functions. For example, this could be used for conditional
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to stay away from the specifics of the example this early in the doc. I'll give a better example below

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my updates

execution of a software deployment:

```powershell
npm run build && npm run deploy
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A better example might be this:

# Create a new SSH key pair and if successful, copy the public key to the clipboard
ssh-keygen -t rsa -b 2048 && Get-Content -Raw ~\.ssh\id_rsa.pub | clip

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my updates

@opbld32
Copy link

opbld32 commented Oct 2, 2019

Docs Build status updates of commit fae3c77:

⚠️ Validation status: warnings

File Status Preview URL Details
reference/7/Microsoft.PowerShell.Core/About/about_Operators.md ⚠️Warning View (powershell-7) Details
reference/7/Microsoft.PowerShell.Core/About/about_Pipeline_Chain_Operators.md ⚠️Warning View (powershell-7) Details

reference/7/Microsoft.PowerShell.Core/About/about_Operators.md

  • [Warning] Metadata with following name(s) are not allowed to be set in Yaml header, or as file level metadata in docfx.json, or as global metadata in docfx.json: locale. They are generated by Docs platform, so the values set in these 3 places will be ignored. Please remove them from all 3 places to resolve the warning.

reference/7/Microsoft.PowerShell.Core/About/about_Pipeline_Chain_Operators.md

  • [Warning] Metadata with following name(s) are not allowed to be set in Yaml header, or as file level metadata in docfx.json, or as global metadata in docfx.json: locale. They are generated by Docs platform, so the values set in these 3 places will be ignored. Please remove them from all 3 places to resolve the warning.

For more details, please refer to the build report.

Note: If you changed an existing file name or deleted a file, broken links in other files to the deleted or renamed file are listed only in the full build report.

Copy link
Contributor Author

@rjmholt rjmholt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

assigned to variables, or separated as statements.

To use lower precedence syntax within a pipeline chain, consider the use of
parentheses `(...)` or a subexpression `$(...)`.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I omitted a thing here about && and || being left associative (so cmd1 && cmd2 && cmd3 is the same as [cmd1 && cmd2] && cmd3), but wasn't sure if that's too technical here.

It's relevant if you do something like:

Get-Item ./file.txt || Write-Error 'File not found' && Get-Content -Raw ./file.txt

The associativity means that Get-Content will be executed based on the result of Get-Item || Write-Error, so if Get-Item succeeds it is executed, but if it doesn't Write-Error runs, which by definition does not succeed, so Get-Content does not succeed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to a note about associativity. Can associativity be altered using paretheses or braces? For example:

(Get-Item ./file.txt || Write-Error 'File not found') && Get-Content -Raw ./file.txt
{Get-Item ./file.txt || Write-Error 'File not found'} && Get-Content -Raw ./file.txt

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parentheses currently don't work nicely because they always set $? to $true... That's always been the case unfortunately, although this feature has many people talking about changing it.

Unfortunately the dot-sourced scriptblock also suffers from this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I've added a note about associativity, plus a bit about (...) etc setting $?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thanks

@opbld33
Copy link

opbld33 commented Oct 3, 2019

Docs Build status updates of commit 8a14926:

⚠️ Validation status: warnings

File Status Preview URL Details
reference/7/Microsoft.PowerShell.Core/About/about_Operators.md ⚠️Warning View (powershell-7) Details
reference/7/Microsoft.PowerShell.Core/About/about_Pipeline_Chain_Operators.md ⚠️Warning View (powershell-7) Details

reference/7/Microsoft.PowerShell.Core/About/about_Operators.md

  • [Warning] Metadata with following name(s) are not allowed to be set in Yaml header, or as file level metadata in docfx.json, or as global metadata in docfx.json: locale. They are generated by Docs platform, so the values set in these 3 places will be ignored. Please remove them from all 3 places to resolve the warning.

reference/7/Microsoft.PowerShell.Core/About/about_Pipeline_Chain_Operators.md

  • [Warning] Metadata with following name(s) are not allowed to be set in Yaml header, or as file level metadata in docfx.json, or as global metadata in docfx.json: locale. They are generated by Docs platform, so the values set in these 3 places will be ignored. Please remove them from all 3 places to resolve the warning.

For more details, please refer to the build report.

Note: If you changed an existing file name or deleted a file, broken links in other files to the deleted or renamed file are listed only in the full build report.

@DCtheGeek DCtheGeek modified the milestones: 7.0.0, Future Oct 17, 2019
@sdwheeler sdwheeler added area-language Area - PowerShell syntax and keywords and removed hold-for-pr Waiting - for PR merge labels Oct 18, 2019
@sdwheeler sdwheeler modified the milestones: Future, 7.0.0 Oct 18, 2019
@opbld31
Copy link

opbld31 commented Oct 18, 2019

Docs Build status updates of commit cc4c93c:

⚠️ Validation status: warnings

File Status Preview URL Details
reference/7/Microsoft.PowerShell.Core/About/about_Operators.md ⚠️Warning View (powershell-7) Details
reference/7/Microsoft.PowerShell.Core/About/about_Pipeline_Chain_Operators.md ⚠️Warning View (powershell-7) Details

reference/7/Microsoft.PowerShell.Core/About/about_Operators.md

  • [Warning] Metadata with following name(s) are not allowed to be set in Yaml header, or as file level metadata in docfx.json, or as global metadata in docfx.json: locale. They are generated by Docs platform, so the values set in these 3 places will be ignored. Please remove them from all 3 places to resolve the warning.

reference/7/Microsoft.PowerShell.Core/About/about_Pipeline_Chain_Operators.md

  • [Warning] Metadata with following name(s) are not allowed to be set in Yaml header, or as file level metadata in docfx.json, or as global metadata in docfx.json: locale. They are generated by Docs platform, so the values set in these 3 places will be ignored. Please remove them from all 3 places to resolve the warning.

For more details, please refer to the build report.

Note: If you changed an existing file name or deleted a file, broken links in other files to the deleted or renamed file are listed only in the full build report.

@sdwheeler sdwheeler merged commit ec886a1 into MicrosoftDocs:staging Oct 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Area - PowerShell syntax and keywords
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document &&/|| operators
8 participants