Nushell
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
GitHub
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
GitHub
  • Categories

    • Bits
    • Bytes
    • Chart
    • Conversions
    • Core
    • Database
    • Dataframe
    • Dataframe Or Lazyframe
    • Date
    • Debug
    • Default
    • Env
    • Experimental
    • Expression
    • Filesystem
    • Filters
    • Formats
    • Generators
    • Hash
    • History
    • Lazyframe
    • Math
    • Misc
    • Network
    • Path
    • Platform
    • Plugin
    • Prompt
    • Random
    • Removed
    • Shells
    • Strings
    • System
    • Viewers

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
  • --capture-errors, -c: catch errors as the closure runs, and return them
  • --env: keep the environment defined inside the command

Parameters

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

Input/output types:

inputoutput
anyany

Examples

Run the closure

> do { echo hello }
hello

Run a stored first-class closure

> let text = "I am enclosed"; let hello = {|| echo $text}; do $hello
I am enclosed

Run the closure and ignore both shell and external program errors

> do --ignore-errors { thisisnotarealcommand }

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

> do --capture-errors { nu --commands 'exit 1' } | myscarycommand

Run the closure with a positional, type-checked parameter

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

Run the closure with pipeline input

> 77 | do { 100 + $in }
177

Run the closure with a default parameter value

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

Run the closure with two positional parameters

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

Run the closure and keep changes to the environment

> do --env { $env.foo = 'bar' }; $env.foo
bar