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 used only in command signatures
          • 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 a for loop) return null. An if without an else also returns null when its condition is false.

  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   # prints nothing
    "null" | from json | describe
    # => nothing
  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

    By default, ignore discards only the standard output. An external command's stderr, such as git's Switched to branch 'featurebranch' message, is still shown. Use ignore --stdout --stderr to discard both.

  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'
    # =>    ╭─[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` command
  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.

    let missing_value = [{a:1 b:2} {b:1}]
    $missing_value.1.a? | describe
    # => nothing

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