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
  • Introduction
  • Installation
    • Default Shell
  • Getting Started
    • Quick Tour
    • Moving Around the System
    • Thinking in Nu
    • Nushell Cheat Sheet
  • Nu Fundamentals
    • Types of Data
    • Loading Data
    • Data Formats
    • Working with SQLite
    • Pipelines
    • Working with Strings
    • Regular Expressions
    • Working with Binary Data
    • Working with Lists
    • Working with Records
    • Working with Numbers
    • Working with Tables
    • Working with Paths
    • Navigating and Accessing Structured Data
    • Special Variables
  • Programming in Nu
    • Custom Commands
    • Aliases
    • Operators
    • Variables
    • Control Flow
    • Scripts
    • Modules
      • Using Modules
      • Creating Modules
    • Overlays
    • Sorting
    • Testing your Nushell Code
    • Debugging Scripts
    • Language Server
    • Best Practices
  • Nu as a Shell
    • Configuration
    • Configuration Reference
    • Environment
    • Stdout, Stderr, and Exit Codes
    • Working with the Terminal
    • Running System (External) Commands
    • How to Configure 3rd Party Prompts
    • Directory Stack
    • Reedline, Nu's Line Editor
    • Custom Completions
    • Externs
    • Coloring and Theming in Nu
    • Hooks
    • Background Jobs
  • Coming to Nu
    • Coming from Bash
    • Coming from CMD.EXE
    • Coming from PowerShell
    • Nu map from other shells and domain specific languages
    • Nu Map from Imperative Languages
    • Nu Map from Functional Languages
    • Nushell operator map
  • Design Notes
    • How Nushell Code Gets Run
  • (Not So) Advanced
    • Standard Library
      • std/assert
      • std/bench
      • std/clip
      • std/config
      • std/dt
      • std/formats
      • std/help
      • std/input
      • std/iter
      • std/log
      • std/math
      • std/random
      • std/util
      • std/xml
      • std-rfc
    • Dataframes
      • Dataframe Operations
      • Column Selectors
      • Math Expressions
      • String Expressions
      • Dates and Times in Dataframes
      • Masks and Conditionals
      • Aggregations and Window Functions
    • Metadata
    • Creating Your Own Errors
    • Parallelism
    • Plugins
    • explore
    • Building TUIs with tui
    • MCP Server

std/util

The std/util module holds commands that don't belong to any other module. Import it with a glob, so they have no prefix:

use std/util *

You can also import a single command, as in use std/util "path add". After use std/util without the glob, the commands are util path add, util repeat and so on, and after use std, they are std path add, std repeat and so on, without util.

  • path add
  • repeat
  • null-device and null_device
  • structure
  • ellie

path add

path add adds directories to the front of $env.PATH, or to the end with --append. It is described in Path Configuration.

repeat

repeat returns a list that holds its input n times:

"ab" | repeat 3 | to nuon
# => [ab, ab, ab]
"-" | repeat 10 | str join
# => ----------

The input can be any value, and each item of the list is a copy of it. With 0, the result is an empty list. A negative number is an error:

"ab" | repeat -1
# => Error: nu::shell::error
# =>
# =>   × invalid_argument
# =>    ╭─[repl_entry #1:1:15]
# =>  1 │ "ab" | repeat -1
# =>    ·               ─┬
# =>    ·                ╰── n should be a positive integer, found -1
# =>    ╰────

Without input, repeat 2 returns [null, null].

null-device and null_device

null-device returns the path of the system's null device, /dev/null, or \\.\NUL on Windows. Whatever is written there is thrown away, so use it to discard a stream, as in File Redirections:

cat unknown.txt e> (null-device)

null_device is a constant with the same path. Use the constant where Nushell needs a value while it parses the code, such as a parameter's default value. Writing --log: path = (null-device) there fails with "Default values should be constant expressions", but the constant works:

use std/util [null_device]
def build [--log: path = $null_device] { $log }
build
# => /dev/null

After use std/util without the *, the constant is $util.null_device. After use std, it is $std.null_device.

structure

structure takes a command line as a string argument and splits it into a table of tokens, with their text, kind and span. It is meant for custom completers that receive the whole command line. See Context Aware Custom Completions.

ellie

ellie returns Ellie, Nushell's elephant mascot, as a string of ASCII art in green:

ellie
# =>      __  ,
# =>  .--()°'.'
# => '|, . ,'
# =>  !_-(_\

It is the same drawing that the welcome banner shows.

Edit this page on GitHub
Contributors: fdncred
Prev
std/random
Next
std/xml