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
  • Categories

    • Bits
    • Bytes
    • Chart
    • Conversions
    • Core
    • Database
    • Dataframe
    • Dataframe Or Lazyframe
    • Date
    • Debug
    • Default
    • Env
    • Experimental
    • Expression
    • Filesystem
    • Filters
    • Formats
    • Generators
    • Hash
    • History
    • Lazyframe
    • Math
    • Misc
    • Network
    • Path
    • Platform
    • Plugin
    • Prompt
    • Random
    • Removed
    • Shells
    • Strings
    • System
    • Viewers

math sum for math

Returns the sum of a list of numbers or of each column in a table.

Signature

> math sum {flags} ...rest

Parameters

  • ...rest: The cell-paths/columns to operate on.

Input/output types:

inputoutput
list<number>number
list<duration>duration
list<filesize>filesize
rangenumber
tablerecord
recordrecord

Examples

Sum a list of numbers.

> [1 2 3] | math sum
6

Get the disk usage for the current directory.

> ls | get size | math sum

Compute the sum of each column in a table.

> [[a b]; [1 2] [3 4]] | math sum
╭───┬───╮
│ a │ 4 │
│ b │ 6 │
╰───┴───╯

Sum the values of list-valued columns in a record.

> {alice: [1 2 3], bob: [4 5 6]} | math sum
╭───────┬────╮
│ alice │ 6  │
│ bob   │ 15 │
╰───────┴────╯

Sum a single column using a cell path.

> {alice: [1 2 3], bob: [4 5 6]} | math sum alice
╭───────┬───────────╮
│ alice │ 6         │
│       │ ╭───┬───╮ │
│ bob   │ │ 0 │ 4 │ │
│       │ │ 1 │ 5 │ │
│       │ │ 2 │ 6 │ │
│       │ ╰───┴───╯ │
╰───────┴───────────╯