Document pipeline chain operators (&&/||)#4856
Document pipeline chain operators (&&/||)#4856sdwheeler merged 9 commits intoMicrosoftDocs:stagingfrom
Conversation
|
Docs Build status updates of commit 2f31955:
|
| File | Status | Preview URL | Details |
|---|---|---|---|
| reference/7/Microsoft.PowerShell.Core/About/about_Operators.md | View (powershell-7) | Details | |
| reference/7/Microsoft.PowerShell.Core/About/about_Pipeline_Chain_Operators.md | 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.
|
Docs Build status updates of commit 741e1af:
|
| File | Status | Preview URL | Details |
|---|---|---|---|
| reference/7/Microsoft.PowerShell.Core/About/about_Operators.md | View (powershell-7) | Details | |
| reference/7/Microsoft.PowerShell.Core/About/about_Pipeline_Chain_Operators.md | 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.
|
Docs Build status updates of commit 118a564:
|
| File | Status | Preview URL | Details |
|---|---|---|---|
| reference/7/Microsoft.PowerShell.Core/About/about_Operators.md | View (powershell-7) | Details | |
| reference/7/Microsoft.PowerShell.Core/About/about_Pipeline_Chain_Operators.md | 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.
|
Docs Build status updates of commit 3c5eb02:
|
| File | Status | Preview URL | Details |
|---|---|---|---|
| reference/7/Microsoft.PowerShell.Core/About/about_Operators.md | View (powershell-7) | Details | |
| reference/7/Microsoft.PowerShell.Core/About/about_Pipeline_Chain_Operators.md | 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: |
There was a problem hiding this comment.
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.
| In this example the `npm run deploy` command only runs if the build command | ||
| succeeds. | ||
|
|
||
| > [!NOTE] |
There was a problem hiding this comment.
I would put this note immediately under the Long Description
|
Docs Build status updates of commit ab5ef75:
|
| File | Status | Preview URL | Details |
|---|---|---|---|
| reference/7/Microsoft.PowerShell.Core/About/about_Operators.md | View (powershell-7) | Details | |
| reference/7/Microsoft.PowerShell.Core/About/about_Pipeline_Chain_Operators.md | 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.
|
Docs Build status updates of commit 9bbf66a:
|
| File | Status | Preview URL | Details |
|---|---|---|---|
| reference/7/Microsoft.PowerShell.Core/About/about_Operators.md | View (powershell-7) | Details | |
| reference/7/Microsoft.PowerShell.Core/About/about_Pipeline_Chain_Operators.md | 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.
9bbf66a to
211ba99
Compare
|
Docs Build status updates of commit 211ba99:
|
| File | Status | Preview URL | Details |
|---|---|---|---|
| reference/7/Microsoft.PowerShell.Core/About/about_Operators.md | View (powershell-7) | Details | |
| reference/7/Microsoft.PowerShell.Core/About/about_Pipeline_Chain_Operators.md | 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.
|
|
||
| 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 |
There was a problem hiding this comment.
I want to stay away from the specifics of the example this early in the doc. I'll give a better example below
| execution of a software deployment: | ||
|
|
||
| ```powershell | ||
| npm run build && npm run deploy |
There was a problem hiding this comment.
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|
Docs Build status updates of commit fae3c77:
|
| File | Status | Preview URL | Details |
|---|---|---|---|
| reference/7/Microsoft.PowerShell.Core/About/about_Operators.md | View (powershell-7) | Details | |
| reference/7/Microsoft.PowerShell.Core/About/about_Pipeline_Chain_Operators.md | 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.
| assigned to variables, or separated as statements. | ||
|
|
||
| To use lower precedence syntax within a pipeline chain, consider the use of | ||
| parentheses `(...)` or a subexpression `$(...)`. |
There was a problem hiding this comment.
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.txtThe 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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Ok, I've added a note about associativity, plus a bit about (...) etc setting $?
|
Docs Build status updates of commit 8a14926:
|
| File | Status | Preview URL | Details |
|---|---|---|---|
| reference/7/Microsoft.PowerShell.Core/About/about_Operators.md | View (powershell-7) | Details | |
| reference/7/Microsoft.PowerShell.Core/About/about_Pipeline_Chain_Operators.md | 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.
|
Docs Build status updates of commit cc4c93c:
|
| File | Status | Preview URL | Details |
|---|---|---|---|
| reference/7/Microsoft.PowerShell.Core/About/about_Operators.md | View (powershell-7) | Details | |
| reference/7/Microsoft.PowerShell.Core/About/about_Pipeline_Chain_Operators.md | 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.
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
Reason(s) for not updating all version of documents