peek for default
Peek the first <n> elements of a stream and store them in the metadata.
Signature
> peek {flags} (n)
Parameters
-
n: Number of elements to peek, if the input is a stream or list.
Input/output types:
| input | output |
|---|---|
| list<any> | list<any> |
| table | table |
| any | any |
Examples
Peek the first 2 elements of a stream.
> seq 1 5 | peek 2 | metadata | $in.peek ╭────────┬───────────╮ │ type │ list │ │ stream │ true │ │ │ ╭───┬───╮ │ │ value │ │ 0 │ 1 │ │ │ │ │ 1 │ 2 │ │ │ │ ╰───┴───╯ │ ╰────────┴───────────╯
Lists can also be peeked.
> [1, 2, 3] | peek 1 | metadata | $in.peek ╭────────┬───────────╮ │ type │ list │ │ stream │ false │ │ │ ╭───┬───╮ │ │ value │ │ 0 │ 1 │ │ │ │ ╰───┴───╯ │ ╰────────┴───────────╯
Peeking non-list values won't return any values.
> 'hello' | peek 1 | metadata | $in.peek ╭────────┬───────╮ │ type │ value │ │ stream │ false │ ╰────────┴───────╯
Peeking non-list streams (text streams, binary streams, external byte streams) won't return any values.
> [0x[11] 0x[13 15]] | bytes collect | peek | metadata | $in.peek ╭────────┬────────╮ │ type │ binary │ │ stream │ true │ ╰────────┴────────╯
Copyright © 2019–2026 The Nushell Project DevelopersLicensed under the MIT License.
https://www.nushell.sh/commands/docs/peek.html