Redirecting Output in Nushell

#Nushell

I've recently switched my default shell to Nushell in an attempt to bring type safety to my shell experience. This has been a big win so far, but there are some downsides to Nushell.

While a deliberate design decision, not all POSIX shell operations can be translated directly to Nushell. Today, I learned that the standard redirection operator > has a different meaning.

I wanted to deploy a simple nginx pod to my Kubernetes home lab. Using the --dry-run=client flag, I aimed to generate and then edit the resulting YAML file:

kubectl run nginx-yaml --image=nginx --dry-run=client -oyaml > nginx.yaml

This operation silently failed. In other shells such as bash or zsh, the above command would redirect the stdout YAML to the file nginx.yaml.

However, running the same command in Nushell prints the following to stdout:

1apiVersion: v1
2kind: Pod
3metadata:
4  creationTimestamp: null
5  labels:
6    run: nginx-yaml
7  name: nginx-yaml
8spec:
9  containers:
10  - args:
11    - '>'
12    - out.yaml
13    image: nginx
14    name: nginx-yaml
15    resources: {}
16  dnsPolicy: ClusterFirst
17  restartPolicy: Always
18status: {}
19

Interestingly, even though the > redirection operator doesn't exist in Nushell, the command actually succeeds.

Let's explore why that is the case.

The > is treated as a raw argument to the kubectl run command. So ">" and "out.yaml" become arguments of the kubectl run command and hence become part of the generated YAML spec. kubectl was expecting an argument for the entrypoint in spec.container.args after the --image flag.

I then learned to pipe to Nushells built-in save command, rather than using the familiar Unix redirection patterns:

k run nginx-yaml --image=nginx --dry-run=client -oyaml | save nginx.yaml

Let me know if you've encountered similar curiosities when working with Nushell.

Thanks for visiting. © 2025. Stay curious, keep coding. 🚀