Skip to content

Commit db1670b

Browse files
authored
Clarify pipeline arguments/output in book (#1287)
* Clarify pipeline arguments/output in book * Elaborate on help command for pipe arguments
1 parent 3c664a3 commit db1670b

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

book/pipelines.md

+58
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,64 @@ Data coming from an external command into Nu will come in as bytes that Nushell
6666

6767
Nu works with data piped between two external commands in the same way as other shells, like Bash would. The `stdout` of external_command_1 is connected to the `stdin` of external_command_2. This lets data flow naturally between the two commands.
6868

69+
### Notes on errors when piping commands
70+
71+
Sometimes, it might be unclear as to why you cannot pipe to a command.
72+
73+
For example, PowerShell users may be used to piping the output of any internal PowerShell command directly to another, e.g.:
74+
75+
`echo 1 | sleep`
76+
77+
(Where for PowerShell, `echo` is an alias to `Write-Output` and `sleep` is to `Start-Sleep`.)
78+
79+
However, it might be surprising that for some commands, the same in Nushell errors:
80+
81+
```nu
82+
> echo 1sec | sleep
83+
Error: nu::parser::missing_positional
84+
85+
× Missing required positional argument.
86+
╭─[entry #53:1:1]
87+
1 │ echo 1sec | sleep
88+
╰────
89+
help: Usage: sleep <duration> ...(rest) . Use `--help` for more information.
90+
```
91+
92+
While there is no steadfast rule, Nu generally tries to copy established conventions,
93+
or do what 'feels right'. And with `sleep`, this is actually the same behaviour as Bash.
94+
95+
Many commands do have piped input/output however, and if it's ever unclear,
96+
you can see what you can give to a command by invoking `help <command name>`:
97+
98+
```nu
99+
> help sleep
100+
Delay for a specified amount of time.
101+
102+
Search terms: delay, wait, timer
103+
104+
Usage:
105+
> sleep <duration> ...(rest)
106+
107+
Flags:
108+
-h, --help - Display the help message for this command
109+
110+
Parameters:
111+
duration <duration>: Time to sleep.
112+
...rest <duration>: Additional time.
113+
114+
Input/output types:
115+
╭───┬─────────┬─────────╮
116+
│ # │ input │ output │
117+
├───┼─────────┼─────────┤
118+
│ 0 │ nothing │ nothing │
119+
╰───┴─────────┴─────────╯
120+
```
121+
122+
In this case, sleep takes `nothing` and instead expects an argument.
123+
124+
So, we can supply the output of the `echo` command as an argument to it:
125+
`echo 1sec | sleep $in` or `sleep (echo 1sec)`
126+
69127
## Behind the scenes
70128

71129
You may have wondered how we see a table if [`ls`](/commands/docs/ls.md) is an input and not an output. Nu adds this output for us automatically using another command called [`table`](/commands/docs/table.md). The [`table`](/commands/docs/table.md) command is appended to any pipeline that doesn't have an output. This allows us to see the result.

0 commit comments

Comments
 (0)