43

I'm using OS X Mavericks with zsh (technically the package oh-my-zsh).

I've been facing this bug for some time now and haven't found a way to fix it. Sometimes when I pipe a command it just says command not found.

For example, when I do a nmap network list scan like so nmap -sL 192.168.2.0/24 | grep ')' I sometimes get the error zsh: command not found:  grep. Even when I use arrow up button it won't work, so I have to rewrite the command, exactly the same, and it will work.

It is really annoying and it has happened occasionally with other commands and mostly after a pipe.

Any idea why this is occurring?

AlG
  • 14,697
  • 4
  • 41
  • 54
Obi-Wan
  • 846
  • 1
  • 11
  • 26
  • Possible duplicate of [Bash piping in OSX prompts command not found, sometimes](https://stackoverflow.com/questions/8694442/bash-piping-in-osx-prompts-command-not-found-sometimes) – tripleee Nov 14 '17 at 12:57

2 Answers2

172

The fact that it's happening only sometimes indicates that your input actually varies (subtly) from time to time.

It depends on what kind of keyboard you have, but I think it's likely that you're accidentally holding down the Alt key while you type the space after the pipe. Alt+Space is a non-breaking space, which zsh won't recognise.

Stephan
  • 2,863
  • 1
  • 17
  • 14
24

This is common error which happened in mac OS X when you copy ans paste command line. what you can do is to delete the space before and after the |

for example kubectl get pods | grep bla-bla-bla is now kubectl get pods|grep bla-bla-bla

hope that's help

thelastworm
  • 544
  • 4
  • 14