Home Explore Blog CI



nushell

2nd chunk of `lang-guide/chapters/pipelines.md`
db002fea1c4f16b48e9db6ce049477400ebbf1d330eeb6ea0000000100000992
But you can't use redirection along with `o+e>|`, because it's ambiguous:

```nu
nu demo.nu o> file.txt o+e>| str upcase
```

Also note that `complete` is special, it doesn't work with `e>|`, `o+e>|`.

## Stdio and redirection behavior examples

Pipeline and redirection behavior can be hard to follow when they are used with subexpressions, or custom commands. Here are some examples that show intended stdio behavior.

### Examples for subexpression

- (^cmd1 | ^cmd2; ^cmd3 | ^cmd4)

| Command | Stdout     | Stderr   |
| ------- | ---------- | -------- |
| cmd1    | Piped      | Terminal |
| cmd2    | _Terminal_ | Terminal |
| cmd3    | Piped      | Terminal |
| cmd4    | Terminal   | Terminal |

- (^cmd1 | ^cmd2; ^cmd3 | ^cmd4) | ^cmd5

It runs `(^cmd1 | ^cmd2; ^cmd3 | ^cmd4)` first, then pipes _stdout_ to `^cmd5`, where both stdout and stderr are directed to the Terminal.

| Command | Stdout     | Stderr   |
| ------- | ---------- | -------- |
| cmd1    | Piped      | Terminal |
| cmd2    | _Terminal_ | Terminal |
| cmd3    | Piped      | Terminal |
| cmd4    | Piped      | Terminal |

- (^cmd1 | ^cmd2; ^cmd3 | ^cmd4) e>| ^cmd5

It runs `(^cmd1 | ^cmd2; ^cmd3 | ^cmd4)` first, then pipes _stderr_ to `^cmd5`, where both stdout and stderr are directed to the Terminal.

| Command | Stdout   | Stderr   |
| ------- | -------- | -------- |
| cmd1    | Piped    | Terminal |
| cmd2    | Terminal | Terminal |
| cmd3    | Piped    | Terminal |
| cmd4    | Terminal | Piped    |

- (^cmd1 | ^cmd2; ^cmd3 | ^cmd4) o+e>| ^cmd5

It runs `(^cmd1 | ^cmd2; ^cmd3 | ^cmd4)` first, then pipes _stdout and stderr_ to `^cmd5`, where both stdout and stderr are directed to the Terminal.

| Command | Stdout   | Stderr   |
| ------- | -------- | -------- |
| cmd1    | Piped    | Terminal |
| cmd2    | Terminal | Terminal |
| cmd3    | Piped    | Terminal |
| cmd4    | Piped    | Piped    |

- (^cmd1 | ^cmd2; ^cmd3 | ^cmd4) o> test.out

| Command | Stdout | Stderr   |
| ------- | ------ | -------- |
| cmd1    | Piped  | Terminal |
| cmd2    | File   | Terminal |
| cmd3    | Piped  | Terminal |
| cmd4    | File   | Terminal |

- (^cmd1 | ^cmd2; ^cmd3 | ^cmd4) e> test.out

| Command | Stdout   | Stderr |
| ------- | -------- | ------ |
| cmd1    | Piped    | File   |
| cmd2    | Terminal | File   |
| cmd3    | Piped    | File   |
| cmd4    | Terminal | File   |

- (^cmd1 | ^cmd2; ^cmd3 | ^cmd4) o+e> test.out

| Command | Stdout | Stderr |

Title: Examples of Standard I/O and Redirection Behavior with Subexpressions
Summary
This section provides examples that illustrate the behavior of standard input/output (stdio) and redirection, particularly when used with subexpressions in Nushell pipelines. It covers scenarios involving piping stdout or stderr to subsequent commands and redirecting output to files. The examples demonstrate how different commands within the subexpression direct their stdout and stderr, providing a table format to clarify the behavior of each command in relation to the terminal, pipes, and files.