Skip to content

Commit 6b2ff54

Browse files
authored
For semicolon stdout redirection, contrast external to internal (#2202)
1 parent 0380f60 commit 6b2ff54

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

book/stdout_stderr_exit_codes.md

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

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`.
102+
Semicolons follow defined pipeline behavior. In the following example, the first external command prints to stdout, and the second external command stdout becomes the output of the parentheses-subexpression and gets piped into `out.txt`.
103103
```nu
104-
let text = "hello\nworld"
105-
($text | head -n 1; $text | tail -n 1) o> out.txt
104+
(nu -c 'print hello'; nu -c 'print world') o> test.txt
106105
# => hello
107106
open out.txt
108107
# => world
@@ -117,6 +116,13 @@ open out.txt
117116
# => world
118117
```
119118

119+
This external command behavior is in contrast to native Nushell expressions where the first command's stdout gets discarded:
120+
```nu
121+
('hello'; 'world') o> test.txt
122+
open test.txt
123+
# => world
124+
```
125+
120126
## Pipe Redirections
121127

122128
If a regular pipe `|` comes after an external command, it redirects the stdout of the external command as input to the next command. To instead redirect the stderr of the external command, you can use the stderr pipe, `err>|` or `e>|`:

0 commit comments

Comments
 (0)