module

Define a custom module

Signature

> module (module_name) (block)

Parameters

  • module_name: module name
  • block: body of the module

Notes

This command is a parser keyword. For details, check:
  https://www.nushell.sh/book/thinking_in_nushell.html

Examples

Define a custom command in a module and call it

> module spam { export def foo [] { "foo" } }; use spam foo; foo

Define an environment variable in a module and evaluate it

> module foo { export env FOO_ENV { "BAZ" } }; use foo FOO_ENV; $env.FOO_ENV

Define a custom command that participates in the environment in a module and call it

> module foo { export def-env bar [] { let-env FOO_BAR = "BAZ" } }; use foo bar; bar; $env.FOO_BAR