W3cubDocs

/Nushell

def for core

Define a custom command.

Signature

> def {flags} (def_name) (params) (body)

Parameters

  • def_name: definition name
  • params: parameters
  • body: body of the definition

Input/output types:

input output
nothing nothing

Examples

Define a command and run it

>defsay-hi [] { echo'hi' };say-hi
hi

Define a command and run it with parameter(s)

>defsay-sth [sth: string] { echo$sth };say-sthhi
hi

Notes

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

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