Skip to content

Commit e28fa1d

Browse files
authored
Fix outdated output redirection docs (#2200)
The 0.92.0 release notes document the behavior previously documented here. Update to current behavior. The 0.92.0 release notes > File redirections (`o>`, `e>`, `o+e>`, etc.) now apply to all ***external*** commands inside an expression. I searched this repository for ` e> `, ` o> `, ` err> `, ` out> `, `subexpression`, `piping`. I was not able to identify release notes that document changed behavior after 0.92.0, and checked the [0.92.0 PR](nushell/nushell#11934) for linked followups or comments. Resolves #2152 Resolves nushell/nushell#17604
1 parent ec8d907 commit e28fa1d

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

book/stdout_stderr_exit_codes.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,23 @@ use std
9999
cat unknown.txt o+e> (std null-device)
100100
```
101101

102-
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`:
102+
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`.
103103
```nu
104104
let text = "hello\nworld"
105105
($text | head -n 1; $text | tail -n 1) o> out.txt
106+
# => hello
107+
open out.txt
108+
# => world
109+
```
110+
111+
To combine the output, scope them into a block and execute it with `do`:
112+
```nu
113+
let text = "hello\nworld"
114+
do { $text | head -n 1; $text | tail -n 1 } o> out.txt
115+
open out.txt
116+
# => hello
117+
# => world
106118
```
107-
Pipes and additional file redirections inside the expression will override any file redirections applied from the outside.
108119

109120
## Pipe Redirections
110121

0 commit comments

Comments
 (0)