Search

Dark theme | Light theme

November 6, 2025

Nushell Niceties: Checking For Emptiness

To check if a value is empty you can use the is-empty command. The command can be used for string values, lists and records.
The opposite check to see if a value is not empty can be done with the is-not-empty command. Just like with the is-empty command this can be used for string values, lists and records. To check if values in a table column are not empty the names of the columns to check can be passed as argument.

In the following example several uses of is-empty and is-not-empty are shown:

use std/assert

# Empty string value
assert ('' | is-empty)

# Empty list
assert ([] | is-empty)

# Empty record
assert ({} | is-empty)

# Evaluate is-empty for all rows.
assert ([[name type]; [Nushell ''] [bash '']] | all { |row| $row.type | is-empty })


# Non-empty string value
assert ('Nushell' | is-not-empty)

# Non-empty list
assert ([Nushell rocks] | is-not-empty)

# Non-empty record
assert ({name: Nushell type: shell} | is-not-empty)

# Evaluate is-no-empty for all rows.
assert ([[name type]; [Nushell shell] [bash posix]] | all { |row| $row.type | is-not-empty })

Written with Nushell 0.108.0.