W3cubDocs

/Nushell

do for core

Run a closure, providing it with the pipeline input.

Signature

> do {flags} (closure) ...rest

Flags

  • --ignore-errors, -i: ignore errors as the closure runs
  • --ignore-shell-errors, -s: ignore shell errors as the closure runs
  • --ignore-program-errors, -p: ignore external program errors as the closure runs
  • --capture-errors, -c: catch errors as the closure runs, and return them

Parameters

  • closure: the closure to run
  • ...rest: the parameter(s) for the closure

Input/output types:

input output
any any

Examples

Run the closure

>do { echohello }
hello

Run a stored first-class closure

>lettext="I am enclosed";lethello= {|| echo$text};do$hello
Iamenclosed

Run the closure and ignore both shell and external program errors

>do-i { thisisnotarealcommand }

Run the closure and ignore shell errors

>do-s { thisisnotarealcommand }

Run the closure and ignore external program errors

>do-p { nu-c'exit 1' };echo"I'll still run"

Abort the pipeline if a program returns a non-zero exit code

>do-c { nu-c'exit 1' } |myscarycommand

Run the closure, with a positional parameter

>do {|x| 100+$x } 77
177

Run the closure, with input

>77|do {|x| 100+$in }

Copyright © 2019–2023 The Nushell Project DevelopersLicensed under the MIT License.
https://www.nushell.sh/commands/docs/do.html