Skip to content
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

(GH-10459) Reorganize grouping expression docs #10461

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 31 additions & 29 deletions reference/5.1/Microsoft.PowerShell.Core/About/about_Operators.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: Describes the operators that are supported by PowerShell.
Locale: en-US
ms.date: 09/25/2023
ms.date: 09/26/2023
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-5.1&WT.mc_id=ps-gethelp
schema: 2.0.0
title: about Operators
Expand Down Expand Up @@ -114,6 +114,8 @@ expressions. For example: `(1 + 2) / 3`

However, in PowerShell, there are additional behaviors.

#### Grouping result expressions

`(...)` allows you to let output from a _command_ participate in an expression.
For example:

Expand All @@ -129,6 +131,34 @@ True
> more information about `$?`, see
> [about_Automatic_Variables][06].
sdwheeler marked this conversation as resolved.
Show resolved Hide resolved

#### Piping grouped expressions

When used as the first segment of a pipeline, wrapping a command or expression
in parentheses invariably causes _enumeration_ of the expression result. If the
parentheses wrap a _command_, it's run to completion with all output _collected
in memory_ before the results are sent through the pipeline.

For example, the outputs for these statements are different:

```powershell
PS> ConvertFrom-Json '["a", "b"]' | ForEach-Object { "The value is '$_'" }

The value is 'a b'

PS> (ConvertFrom-Json '["a", "b"]') | ForEach-Object { "The value is '$_'" }

The value is 'a'
The value is 'b'
```

Grouping an expression before piping also ensures that subsequent
object-by-object processing can't interfere with the enumeration the command
uses to produce its output.

For example, piping the output from `Get-ChildItem` to `Rename-Item` can have
unexpected effects where an item is renamed, then discovered again and renamed
a second time.

#### Grouping assignment statements

Ungrouped assignment statements don't output values. When grouping an
Expand Down Expand Up @@ -184,34 +214,6 @@ in the body of the `if` statement.
> between the assignment operator (`=`) and the equality-comparison operator
> (`-eq`).

#### Piping grouped expressions

When used as the first segment of a pipeline, wrapping a command or expression
in parentheses invariably causes _enumeration_ of the expression result. If the
parentheses wrap a _command_, it's run to completion with all output _collected
in memory_ before the results are sent through the pipeline.

For example, the outputs for these statements are different:

```powershell
PS> ConvertFrom-Json '["a", "b"]' | ForEach-Object { "The value is '$_'" }

The value is 'a b'

PS> (ConvertFrom-Json '["a", "b"]') | ForEach-Object { "The value is '$_'" }

The value is 'a'
The value is 'b'
```

Grouping an expression before piping also ensures that subsequent
object-by-object processing can't interfere with the enumeration the command
uses to produce its output.

For example, piping the output from `Get-ChildItem` to `Rename-Item` can have
unexpected effects where an item is renamed, then discovered again and renamed
a second time.

### Subexpression operator `$( )`

Returns the result of one or more statements. For a single result, returns a
Expand Down
26 changes: 14 additions & 12 deletions reference/7.2/Microsoft.PowerShell.Core/About/about_Operators.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: Describes the operators that are supported by PowerShell.
Locale: en-US
ms.date: 09/25/2023
ms.date: 09/26/2023
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-7.2&WT.mc_id=ps-gethelp
schema: 2.0.0
title: about Operators
Expand Down Expand Up @@ -114,6 +114,8 @@ expressions. For example: `(1 + 2) / 3`

However, in PowerShell, there are additional behaviors.

#### Grouping result expressions

`(...)` allows you to let output from a _command_ participate in an expression.
For example:

Expand All @@ -122,6 +124,17 @@ PS> (Get-Item *.txt).Count -gt 10
True
```

#### Piping grouped expressions

When used as the first segment of a pipeline, wrapping a command or expression
in parentheses invariably causes _enumeration_ of the expression result. If the
parentheses wrap a _command_, it's run to completion with all output _collected
in memory_ before the results are sent through the pipeline.

Grouping an expression before piping also ensures that subsequent
object-by-object processing can't interfere with the enumeration the command
uses to produce its output.

#### Grouping assignment statements

Ungrouped assignment statements don't output values. When grouping an
Expand Down Expand Up @@ -177,17 +190,6 @@ in the body of the `if` statement.
> between the assignment operator (`=`) and the equality-comparison operator
> (`-eq`).

#### Piping grouped expressions

When used as the first segment of a pipeline, wrapping a command or expression
in parentheses invariably causes _enumeration_ of the expression result. If the
parentheses wrap a _command_, it's run to completion with all output _collected
in memory_ before the results are sent through the pipeline.

Grouping an expression before piping also ensures that subsequent
object-by-object processing can't interfere with the enumeration the command
uses to produce its output.

### Subexpression operator `$( )`

Returns the result of one or more statements. For a single result, returns a
Expand Down
26 changes: 14 additions & 12 deletions reference/7.3/Microsoft.PowerShell.Core/About/about_Operators.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: Describes the operators that are supported by PowerShell.
Locale: en-US
ms.date: 09/25/2023
ms.date: 09/26/2023
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-7.3&WT.mc_id=ps-gethelp
schema: 2.0.0
title: about Operators
Expand Down Expand Up @@ -114,6 +114,8 @@ expressions. For example: `(1 + 2) / 3`

However, in PowerShell, there are additional behaviors.

#### Grouping result expressions

`(...)` allows you to let output from a _command_ participate in an expression.
For example:

Expand All @@ -122,6 +124,17 @@ PS> (Get-Item *.txt).Count -gt 10
True
```

#### Piping grouped expressions

When used as the first segment of a pipeline, wrapping a command or expression
in parentheses invariably causes _enumeration_ of the expression result. If the
parentheses wrap a _command_, it's run to completion with all output _collected
in memory_ before the results are sent through the pipeline.

Grouping an expression before piping also ensures that subsequent
object-by-object processing can't interfere with the enumeration the command
uses to produce its output.

#### Grouping assignment statements

Ungrouped assignment statements don't output values. When grouping an
Expand Down Expand Up @@ -177,17 +190,6 @@ in the body of the `if` statement.
> between the assignment operator (`=`) and the equality-comparison operator
> (`-eq`).

#### Piping grouped expressions

When used as the first segment of a pipeline, wrapping a command or expression
in parentheses invariably causes _enumeration_ of the expression result. If the
parentheses wrap a _command_, it's run to completion with all output _collected
in memory_ before the results are sent through the pipeline.

Grouping an expression before piping also ensures that subsequent
object-by-object processing can't interfere with the enumeration the command
uses to produce its output.

### Subexpression operator `$( )`

Returns the result of one or more statements. For a single result, returns a
Expand Down
26 changes: 14 additions & 12 deletions reference/7.4/Microsoft.PowerShell.Core/About/about_Operators.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: Describes the operators that are supported by PowerShell.
Locale: en-US
ms.date: 09/25/2023
ms.date: 09/26/2023
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-7.4&WT.mc_id=ps-gethelp
schema: 2.0.0
title: about Operators
Expand Down Expand Up @@ -114,6 +114,8 @@ expressions. For example: `(1 + 2) / 3`

However, in PowerShell, there are additional behaviors.

#### Grouping result expressions

`(...)` allows you to let output from a _command_ participate in an expression.
For example:

Expand All @@ -122,6 +124,17 @@ PS> (Get-Item *.txt).Count -gt 10
True
```

#### Piping grouped expressions

When used as the first segment of a pipeline, wrapping a command or expression
in parentheses invariably causes _enumeration_ of the expression result. If the
parentheses wrap a _command_, it's run to completion with all output _collected
in memory_ before the results are sent through the pipeline.

Grouping an expression before piping also ensures that subsequent
object-by-object processing can't interfere with the enumeration the command
uses to produce its output.

#### Grouping assignment statements

Ungrouped assignment statements don't output values. When grouping an
Expand Down Expand Up @@ -177,17 +190,6 @@ in the body of the `if` statement.
> between the assignment operator (`=`) and the equality-comparison operator
> (`-eq`).

#### Piping grouped expressions

When used as the first segment of a pipeline, wrapping a command or expression
in parentheses invariably causes _enumeration_ of the expression result. If the
parentheses wrap a _command_, it's run to completion with all output _collected
in memory_ before the results are sent through the pipeline.

Grouping an expression before piping also ensures that subsequent
object-by-object processing can't interfere with the enumeration the command
uses to produce its output.

### Subexpression operator `$( )`

Returns the result of one or more statements. For a single result, returns a
Expand Down