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
print
orif
) returnnull
.Commands that do not accept pipeline input have an input signature of
nothing
.null
is similar to JSON's "null". However, whenever Nushell would print thenull
value (outside of a string or data structure), it prints nothing instead.Example:
> null | to json null > "null" | from json # => no output
You can add
ignore
at 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 | ignore
It's important to understand that
null
is 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
null
but 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' ╭─[entry #4:1:32] 1 │ let missing_value = [{a:1 b:2} {b:1}] · ──┬── · ╰── value originates here ╰──── ╭─[entry #6:1:18] 1 │ $missing_value.1.a · ┬ · ╰── cannot find column 'a' ╰────
To 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.