Skip to content

Commit a7ed14b

Browse files
committed
Update docs for 0.92.0 (file, pipes, and io)
1 parent 5e23c92 commit a7ed14b

14 files changed

+153
-208
lines changed

.vuepress/configs/sidebar/en.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const sidebarEn: SidebarConfig = {
4242
'/book/custom_commands.md',
4343
'/book/aliases.md',
4444
'/book/operators.md',
45-
'/book/variables_and_subexpressions.md',
45+
'/book/variables.md',
4646
'/book/control_flow.md',
4747
'/book/scripts.md',
4848
'/book/modules.md',

book/cheat_sheet.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@
412412

413413
> **custom command which takes any number of positional arguments using rest params**
414414
415-
## Variables & Subexpressions
415+
## Variables
416416

417417
```nu
418418
> let val = 42
@@ -475,10 +475,10 @@
475475

476476
```nu
477477
> let big_files = (ls | where size > 10kb)
478-
> $big_files
478+
> $big_files
479479
```
480480

481-
> **using subexp­ression by wrapping the expression with parent­heses ()**
481+
> **assigning the result of a pipeline to a variable**
482482
483483
---
484484

book/control_flow.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Nushell provides several commands that help determine how different groups of code are executed. In programming languages this functionality is often referred to as _control flow_.
44

55
::: tip
6-
One thing to note is that all of the commands discussed on this page use [blocks](/book/types_of_data.html#blocks). This means you can mutate [environmental variables](/book/environment.html) and other [mutable variables](http://localhost:8080/book/variables_and_subexpressions.html#mutable-variables) in them.
6+
One thing to note is that all of the commands discussed on this page use [blocks](/book/types_of_data.html#blocks). This means you can mutate [environmental variables](/book/environment.html) and other [mutable variables](/book/variables.html#mutable-variables) in them.
77
:::
88

99
## Already covered

book/environment.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Individual environment variables are fields of a record that is stored in the `$
8080
BAR
8181
```
8282

83-
Sometimes, you may want to access an environmental variable which might be unset. Consider using the [question mark operator](variables_and_subexpressions.md#variable-paths) to avoid an error:
83+
Sometimes, you may want to access an environmental variable which might be unset. Consider using the [question mark operator](types_of_data.md#optional-cell-paths) to avoid an error:
8484
```nu
8585
> $env.FOO | describe
8686
Error: nu::shell::column_not_found

book/pipelines.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,16 @@ The `$in` variable will collect the pipeline into a value for you, allowing you
2525

2626
## Multi-line pipelines
2727

28-
If a pipeline is getting a bit long for one line, you can enclose it within `(` and `)` to create a subexpression:
28+
If a pipeline is getting a bit long for one line, you can enclose it within parentheses `()`:
2929

3030
```nu
31-
(
31+
let year = (
3232
"01/22/2021" |
3333
parse "{month}/{day}/{year}" |
3434
get year
3535
)
3636
```
3737

38-
Also see [Subexpressions](https://www.nushell.sh/book/variables_and_subexpressions.html#subexpressions)
39-
4038
## Semicolons
4139

4240
Take this example:

book/programming_in_nu.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ Nushell's aliases work in a similar way and are a part of the programming langua
1111
Common operations can, such as addition or regex search, be done with [operators](operators.md).
1212
Not all operations are supported for all data types and Nushell will make sure to let you know.
1313

14-
You can store intermediate results to [variables](variables_and_subexpressions.md) and immediately evaluate subroutines with [subexpressions](variables_and_subexpressions.html#subexpressions).
14+
You can store intermediate results to [variables](variables.md).
15+
Variables can be immutable, mutable, or a parse-time constant.
1516

1617
The last three sections are aimed at organizing your code:
1718

book/stdout_stderr_exit_codes.md

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@ Without the pipeline, Nushell will not do any redirection, allowing it to print
2020

2121
Another common stream that external applications often use to print error messages is stderr. By default, Nushell does not do any redirection of stderr, which means that by default it will print to the screen.
2222

23-
You can force Nushell to do a redirection by using `do { ... } | complete`. For example, if we wanted to call the external above and redirect its stderr, we would write:
24-
25-
```nu
26-
> do { external } | complete
27-
```
28-
2923
## Exit code
3024

3125
Finally, external commands have an "exit code". These codes help give a hint to the caller whether the command ran successfully.
@@ -37,7 +31,7 @@ Nushell tracks the last exit code of the recently completed external in one of t
3731
> $env.LAST_EXIT_CODE
3832
```
3933

40-
The second uses a command called [`complete`](/commands/docs/complete.md).
34+
The second way is to use the [`complete`](/commands/docs/complete.md) command.
4135

4236
## Using the [`complete`](/commands/docs/complete.md) command
4337

@@ -46,7 +40,7 @@ The [`complete`](/commands/docs/complete.md) command allows you to run an extern
4640
If we try to run the external `cat` on a file that doesn't exist, we can see what [`complete`](/commands/docs/complete.md) does with the streams, including the redirected stderr:
4741

4842
```nu
49-
> do { cat unknown.txt } | complete
43+
> cat unknown.txt | complete
5044
╭───────────┬─────────────────────────────────────────────╮
5145
│ stdout │ │
5246
│ stderr │ cat: unknown.txt: No such file or directory │
@@ -72,20 +66,59 @@ The log level for output can be set with the `NU_LOG_LEVEL` environment variable
7266
NU_LOG_LEVEL=DEBUG nu std_log.nu
7367
```
7468

75-
## Using `out>`, `err>` to redirect stdout and stderr to files
69+
## File redirections
7670

77-
If you want to redirect output to file, you can just type something like this:
71+
If you want to redirect stdout of an external command to a file, you can use `out>` followed by a file path. Similarly, you can use `err>` to redirect stderr:
7872

7973
```nu
8074
cat unknown.txt out> out.log err> err.log
8175
```
8276

83-
If you want to redirect both stdout and stderr to the same file, just type something like this:
77+
If you want to redirect both stdout and stderr to the same file, you can use `out+err>`:
8478

8579
```nu
8680
cat unknown.txt out+err> log.log
8781
```
8882

83+
Note that `out` can be shortend to just `o`, and `err` can be shortened to just `e`. So, the following examples are equivalent to the previous ones above:
84+
```nu
85+
cat unknown.txt o> out.log e> err.log
86+
87+
cat unknown.txt o+e> log.log
88+
```
89+
90+
Also, any expression can be used for the file path, as long as it is a string value:
91+
```nu
92+
use std
93+
cat unknown.txt o+e> (std null-device)
94+
```
95+
96+
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`:
97+
```nu
98+
let text = "hello\nworld"
99+
($text | head -n 1; $text | tail -n 1) o> out.txt
100+
```
101+
Pipes and additional file redirections inside the expression will override any file redirections applied from the outside.
102+
103+
## Pipe redirections
104+
105+
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>|`:
106+
107+
```nu
108+
cat unknown.txt e>| str upcase
109+
```
110+
111+
Of course, there is a corresponding pipe for combined stdout and stderr, `out+err>|` or `o+e>|`:
112+
113+
```nu
114+
nu -c 'print output; print -e error' o+e>| str upcase
115+
```
116+
117+
Unlike file redirections, pipe redirections do not apply to all commands inside an expression. Rather, only the last command in the expression is affected. For example, only `cmd2` in the snippet below will have its stdout and stderr redirected by the pipe.
118+
```nu
119+
(cmd1; cmd2) o+e>| cmd3
120+
```
121+
89122
## Raw streams
90123

91124
Both stdout and stderr are represented as "raw streams" inside of Nushell. These are streams of bytes rather than structured data, which are what internal Nushell commands use.

book/table_of_contents.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
- [Custom commands](custom_commands.md) - Creating your own commands
1616
- [Aliases](aliases.md) - How to alias commands
1717
- [Operators](operators.md) - Operators supported by Nushell
18-
- [Variables and subexpressions](variables_and_subexpressions.md) - Working with variables and working with subexpressions
18+
- [Variables](variables.md) - Working with variables
1919
- [Control flow](control_flow.md) - Working with the control flow commands
2020
- [Environment](environment.md) - Working with environment variables
2121
- [Stdout, stderr, and exit codes](stdout_stderr_exit_codes.md) - Working with stdout, stderr, and exit codes

book/thinking_in_nu.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Another common issue is trying to dynamically create the filename to source from
5151
This doesn't work if `my_path` is a regular runtime variable declared with `let`. This would require the
5252
evaluator to run and evaluate the string, but unfortunately Nushell needs this information at compile-time.
5353

54-
However, if `my_path` is a [constant](/book/variables_and_subexpressions#constant-variables), then this
54+
However, if `my_path` is a [constant](/book/variables#constant-variables), then this
5555
would work, since the string can be evaluated at compile-time:
5656

5757
```nu

book/types_of_data.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ Moreover, you can also access entire columns of a table by name, to obtain lists
404404
╰───┴────╯
405405
```
406406

407-
Of course, these resulting lists don't have the column names of the table. To remove columns from a table while leaving it as a table, you'll commonly use the [`select`](/commands/docs/select.md) command with column names:
407+
Of course, these resulting lists don't have the column names of the table. To choose columns from a table while leaving it as a table, you'll commonly use the [`select`](/commands/docs/select.md) command with column names:
408408

409409
```nu
410410
> [{x:0 y:5 z:1} {x:4 y:7 z:3} {x:2 y:2 z:0}] | select y z
@@ -417,7 +417,7 @@ Of course, these resulting lists don't have the column names of the table. To re
417417
╰───┴───┴───╯
418418
```
419419

420-
To remove rows from a table, you'll commonly use the [`select`](/commands/docs/select.md) command with row numbers, as you would with a list:
420+
To get specific rows from a table, you'll commonly use the [`select`](/commands/docs/select.md) command with row numbers, as you would with a list:
421421

422422
```nu
423423
> [{x:0 y:5 z:1} {x:4 y:7 z:3} {x:2 y:2 z:0}] | select 1 2

0 commit comments

Comments
 (0)