Skip to content
Merged
Changes from all commits
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
15 changes: 13 additions & 2 deletions book/stdout_stderr_exit_codes.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,23 @@ use std
cat unknown.txt o+e> (std null-device)
```

Note that file redirections are scoped to an expression and apply to all external commands in the expression. In the example below, `out.txt` will contain `hello\nworld`:
Semicolons follow defined pipeline behavior. In the following example, the first expression prints to stdout, and the second becomes the result of the parentheses-subexpression and gets piped into `out.txt`.
```nu
let text = "hello\nworld"
($text | head -n 1; $text | tail -n 1) o> out.txt
# => hello
open out.txt
# => world
```

To combine the output, scope them into a block and execute it with `do`:
```nu
let text = "hello\nworld"
do { $text | head -n 1; $text | tail -n 1 } o> out.txt
open out.txt
# => hello
# => world
```
Pipes and additional file redirections inside the expression will override any file redirections applied from the outside.

## Pipe Redirections

Expand Down