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
  • Language Reference Guide
    • Readme
    • Types in the Nu Language
      • Basic Types
        • Any
        • Boolean
        • Integer
        • Float
        • Filesize
        • Duration
        • Datetime
        • Range
        • String
        • Record
        • List
        • Table
        • Closure
        • Nothing
        • Binary
        • Glob
        • Cell-Path
      • Other Data Types

        • Types that cannot be used to declare variables
          • Path
        • Types which are not declarable
          • Error
          • CustomValue
          • Block
      • Type signatures
      • Commands that interact with types
    • Operators
    • Flow control
      • if/else
      • loop
      • while
      • match
      • try/catch
      • break
      • return
      • continue
    • Filters
      • each and par-each
      • Filters to select subsets of data
      • where and filter
      • Understanding the difference between get and select
    • Custom Commands
    • Declarations
    • Variable Scope
    • Strings and Text Formatting
    • Helpers and debugging commands
    • Pipelines
    • MIME Types for Nushell

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

  1. Recommended for use as a missing value indicator.

  2. Commands that explicitly do not return a value (such as print or if) return null.

  3. Commands that do not accept pipeline input have an input signature of nothing.

  4. null is similar to JSON's "null". However, whenever Nushell would print the null value (outside of a string or data structure), it prints nothing instead.

    Example:

    > null | to json
    null
    > "null" | from json
    # => no output
  5. You can add ignore at the end of a pipeline to convert any pipeline result to a nothing. This will prevent the command/pipeline's output from being displayed.

    git checkout featurebranch | ignore
  6. 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 │
    ╰───┴────┴───╯
  7. 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'
      ╰────
  8. 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.

Related commands

  • default: Set a default value for missing (null) fields in a record or table
  • compact: Removes null values from a list
Edit this page on GitHub
Contributors: NotTheDr01ds, fdncred, Hofer-Julian, yo-goto
Prev
Closure
Next
Binary