Search code examples
pipezsh

Commands not recognized when right side of pipe


Environment
OS: macOS Sonoma 14.5
Shell: ZSH 5.9
Keyboard: Danish

Problem
When piping two commands (using |) the command on the right side is not recognized. Eventhough it is a builtin command like echo. The weird thing is, that this is only an issue sometimes. When I delete the pipe and write it again a couple of times, eventually it works. I write the pipe on my keyboard with OPTION + i.

Example

heroku config | grep REDIS_URL
zsh: command not found:  grep
heroku config | grep REDIS_URL
REDIS_URL:

The second command worked, but the first didn't. The lines are copied directly from my shell.

Question
Any suggestions on what is going wrong?
And how I can fix this?
Both ChatGPT and Perplexity was to no help.


Solution

  • TL;DR You aren't releasing the option key soon enough, after you type | but before you hit the space bar.


    On macOS, ⌥Space produces U+00A0, a non-breaking space that is not considered whitespace by the shell. When you type that character, you attempt to execute the command  grep, not grep, which you can seen in your error message (^ added for emphasis):

    zsh: command not found:  grep
                           ^^
    

    which is different from

    zsh: command not found: grep 
                           ^
    

    You are typing ⌥i to type the | character. Sometimes, you release the option key soon enough that you type a literal space character; other times, you are holding it too long and get the non-breaking space. That's why the error seems "random".