Skip to content

Commit ca1d13d

Browse files
flying-sheeprgwood
authored andcommitted
Document $in
1 parent c234b3f commit ca1d13d

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

book/custom_commands.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,17 @@ Now, if we call the above command later in a pipeline, we can see what it does w
394394
───┴─────
395395
```
396396

397+
We can also store the input for later use using the `$in` variable:
398+
399+
```nushell
400+
def nullify [...cols] {
401+
let start = $in
402+
$cols | reduce --fold $start { |col, df|
403+
$df | upsert $col null
404+
}
405+
}
406+
```
407+
397408
## Persisting
398409

399410
For information about how to persist custom commands so that they're visible when you start up Nushell, see the [configuration chapter](configuration.md) and add your startup script.

book/pipeline.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,18 @@ The second command, `inc package.version --minor`, is a filter. Filters take the
1616

1717
The last command, `save "Cargo_new.toml"`, is an output (sometimes called a "sink"). An output takes input from the pipeline and does some final operation on it. In our example, we save what comes through the pipeline to a file as the final step. Other types of output commands may take the values and view them for the user.
1818

19+
The `$in` variable will collect the pipeline into a value for you, allowing you to access the whole stream as a parameter:
20+
21+
```nushell
22+
> echo 1 2 3 | $in.1 * $in.2
23+
6
24+
```
25+
1926
## Multi-line pipelines
2027

2128
If a pipeline is getting a bit long for one line, you can enclose it within `(` and `)` to create a subexpression:
2229

23-
```
30+
```nushell
2431
(
2532
"01/22/2021" |
2633
parse "{month}/{day}/{year}" |

0 commit comments

Comments
 (0)