Nothing
| Description: | The nothing type is to be used to represent the absence of another value. |
| Annotation: | nothing |
| Literal Syntax: | null |
| Casts: | ignore |
| See also: | Types of Data - Nothing |
Additional Language Notes
Recommended for use as a missing value indicator.
Commands that explicitly do not return a value (such as
printor aforloop) returnnull. Anifwithout anelsealso returnsnullwhen its condition is false.Commands that do not accept pipeline input have an input signature of
nothing.nullis similar to JSON's "null". However, whenever Nushell would print thenullvalue (outside of a string or data structure), it prints nothing instead.Example:
null | to json # => null "null" | from json # prints nothing "null" | from json | describe # => nothingYou can add
ignoreat the end of a pipeline to convert any pipeline result to anothing. This will prevent the command/pipeline's output from being displayed.git checkout featurebranch | ignoreBy default,
ignorediscards only the standard output. An external command's stderr, such as git'sSwitched to branch 'featurebranch'message, is still shown. Useignore --stdout --stderrto discard both.It's important to understand that
nullis not the same as the absence of a value! It is possible for a table or list to have missing values. Missing values are displayed with a ❎ character in interactive output.let missing_value = [{a:1 b:2} {b:1}] $missing_value # => ╭───┬────┬───╮ # => │ # │ a │ b │ # => ├───┼────┼───┤ # => │ 0 │ 1 │ 2 │ # => │ 1 │ ❎ │ 1 │ # => ╰───┴────┴───╯By default, attempting to access a missing value will not produce
nullbut will instead generate an error:let missing_value = [{a:1 b:2} {b:1}] $missing_value.1.a # => Error: nu::shell::column_not_found # => # => × Cannot find column 'a' # => ╭─[repl_entry #1:1:32] # => 1 │ let missing_value = [{a:1 b:2} {b:1}] # => · ──┬── # => · ╰── value originates here # => 2 │ $missing_value.1.a # => · ┬ # => · ╰── column 'a' is missing in one or more values # => ╰──── # => help: If some rows have this column, try using 'a?' for optional access, or pre-fill using the `default` commandTo safely access a value that may be missing, mark the cell-path member as optional using a question-mark (
?) after the key name. See Navigating and Accessing Structured Data - Handling Missing Data for more details and examples.let missing_value = [{a:1 b:2} {b:1}] $missing_value.1.a? | describe # => nothing