Skip to content

Commit 0e04ad8

Browse files
committed
Document passing arguments to external commands
1 parent 7eab3dd commit 0e04ad8

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

‎book/running_externals.md‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,32 @@ External command (typically `/usr/bin/ls`):
1818
On Windows, `ls` is a PowerShell _alias_ by default, so `^ls` will not find a matching system _command_.
1919
:::
2020

21+
## Passing Arguments
22+
23+
External arguments are separated by Nushell syntax, not by spaces inside a quoted string. Quote a string to keep its spaces inside one argument:
24+
25+
```nu
26+
git commit -m "Update external command documentation"
27+
```
28+
29+
Nushell does not automatically convert a list into external arguments, and passing a list directly produces an error. Use the spread operator (`...`) to pass each list item as its own argument:
30+
31+
```nu
32+
let paths = ["file one.txt" "file two.txt"]
33+
git add ...$paths
34+
```
35+
36+
Here, `git` receives two path arguments, and the space in each path remains part of that argument. See [the spread operator in command calls](operators.md#in-command-calls) for more examples and the complete spreading rules.
37+
38+
The caret can also run an executable whose name or path is stored in a variable:
39+
40+
```nu
41+
let program = "git"
42+
^$program status
43+
```
44+
45+
See [Strings as external commands](working_with_strings.md#strings-as-external-commands) for the supported string forms. An [`extern` declaration](externs.md) can add type checking and completions for a known external command; calling it follows the same argument rules described here.
46+
2147
## Additional Windows Notes
2248

2349
When running an external command on Windows,

0 commit comments

Comments
 (0)