Home Explore Blog CI



nushell

commands/docs/default.md
0a83c2cec8ee0800c67a56527257f16e01488a4f8838320b000000030000079b
---
title: default
categories: |
  filters
version: 0.104.0
filters: |
  Sets a default value if a row's column is missing or null.
usage: |
  Sets a default value if a row's column is missing or null.
editLink: false
contributors: false
---
<!-- This file is automatically generated. Please edit the command in https://github.com/nushell/nushell instead. -->

# `default` for [filters](/commands/categories/filters.md)

<div class='command-title'>Sets a default value if a row&amp;#x27;s column is missing or null.</div>

## Signature

```> default {flags} (default value) (column name)```

## Flags

 -  `--empty, -e`: also replace empty items like "", {}, and []

## Parameters

 -  `default value`: The value to use as a default.
 -  `column name`: The name of the column.


## Input/output types:

| input | output |
| ----- | ------ |
| any   | any    |
## Examples

Give a default 'target' column to all file entries
```nu
> ls -la | default 'nothing' target

```

Get the env value of `MY_ENV` with a default value 'abc' if not present
```nu
> $env | get --ignore-errors MY_ENV | default 'abc'
abc
```

Replace the `null` value in a list
```nu
> [1, 2, null, 4] | each { default 3 }
╭───┬───╮
│ 0 │ 1 │
│ 1 │ 2 │
│ 2 │ 3 │
│ 3 │ 4 │
╰───┴───╯

```

Replace the missing value in the "a" column of a list
```nu
> [{a:1 b:2} {b:1}] | default 'N/A' a
╭───┬─────┬───╮
│ # │  a  │ b │
├───┼─────┼───┤
│ 0 │   1 │ 2 │
│ 1 │ N/A │ 1 │
╰───┴─────┴───╯

```

Replace the empty string in the "a" column of a list
```nu
> [{a:1 b:2} {a:'' b:1}] | default -e 'N/A' a
╭───┬─────┬───╮
│ # │  a  │ b │
├───┼─────┼───┤
│ 0 │   1 │ 2 │
│ 1 │ N/A │ 1 │
╰───┴─────┴───╯

```

Chunks
ca8a46c2 (1st chunk of `commands/docs/default.md`)
Title: default - Nushell command
Summary
The `default` command in Nushell sets a default value for a specified column if the column is missing or contains a null value in a row. It accepts a default value and a column name as input. The `--empty` flag allows replacing empty items as well.