Photo - Brandon Jaramillo

A Nu Shell


Developing across multiple operating systems can be pretty annoying! Mac bash is different than Arch bash, which is different than Windows powershell. 😵‍💫

We can use nu to bring some consistency.

With a Rust toolchain:

cargo install nu

Without a Rust toolchain:

# Windows
winget install nu
# Mac
brew install nu
# Arch Linux
pacman -S nu


Consistent Builtins

Things like cp, rm, and ls work consistently on nu. (Here's looking at rm -rf on Powershell...)


Working with it

Coming from Bash is quite helpful.

nu works slightly differently than other shells in that it separates parsing and evaluation. More in How Nushell Code Gets Run.

Piping to Files

nu doesn't have a > pipe. Instead:

cat floof | save boop

For >>:

cat floof | save -a boop


Loops differ syntactically from bash in several ways.

For example, unpacking all the archives in the parent directory into the current directory:

for archive in (ls .. | where type != dir) { tar xvf $ }

Similar, but unarchiving into named directories:

for archive in (ls | where type != dir) {
    let archive_stem = $ | path parse | get stem
    mkdir $archive_stem
    cd $archive_stem
    let archive_path = ".." | path join $;
    tar xvf $archive_path
    cd ..

Parameter Expansion

Different shells approach parameter expansion differently.

In bash we can do like:

./ --stage 2 dist $(ferrocene/ci/ dist)

While fish it looks like:

./ --stage 2 dist $(ferrocene/ci/ dist | string split " ")

On nu we do this:

./ --stage 2 dist ...(python ferrocene/ci/ dist | split row " ")