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

List

Description:Ordered sequence of zero or more values of any type
Annotation:list
Literal syntax:See below
Casts:N/A
See Also:Working with Lists
Navigating and Accessing Structured Data
Types of Data - Lists

List-literal Syntax

List syntax is very similar to that of arrays in JSON. However, commas are not required to separate values when Nushell can easily distinguish them. The values of a list may be delimited by:

  • Commas

    [ foo, bar, baz ]
    # => ╭───┬─────╮
    # => │ 0 │ foo │
    # => │ 1 │ bar │
    # => │ 2 │ baz │
    # => ╰───┴─────╯
  • Spaces (when unambiguous):

    [ foo bar baz ]
    # => ╭───┬─────╮
    # => │ 0 │ foo │
    # => │ 1 │ bar │
    # => │ 2 │ baz │
    # => ╰───┴─────╯
  • Line breaks:

    [
      foo
      bar
      baz
    ]
    # => ╭───┬─────╮
    # => │ 0 │ foo │
    # => │ 1 │ bar │
    # => │ 2 │ baz │
    # => ╰───┴─────╯

Additional Language Notes

  1. A list is like a vector or array list in other languages.
  2. A list uses 0-based indexing to retrieve values.

Common commands that can be used with list

Since lists, records and tables form the backbone of Nushell's structured nature, there are too many commands to list here. Here are a few:

  • any
  • all
  • get
  • select
  • each, par-each, where, reduce
  • skip, skip until, skip while, take, take until, take while
  • first, last, length
  • insert, update, upsert, append See also the to (subcommands) and from (subcommands) for more examples.
  • where
  • match
    • Can destructure a list

Common operators that can be used with list

  • in and has for set membership (12 in [1 2 3] and [1 2 3] has 12 are equivalent)

    • not-in and not-has for inverse set membership (12 not-in [1 2 3] is the same as not (12 in [1 2 3]))
  • ++ to concatenate two lists

    [1 2] ++ [3 4] | to nuon
    # => [1, 2, 3, 4]

    Both operands must be lists. To add a single value, use append (or wrap the value in a list: $list ++ [$value]).

Edit this page on GitHub
Contributors: NotTheDr01ds, fdncred, Squidroot2
Prev
Record
Next
Table