47

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?

1

2 Answers 2

189

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.

6
  • 26
    holy *hit, you are right. Thank you so much. To easy to be sawn >.<
    – Obi-Wan
    Commented Jan 12, 2016 at 12:40
  • 5
    Elementary, Watson.
    – Esteban
    Commented Jun 23, 2016 at 21:11
  • 2
    Perfect, thanks for this. My terminal does not show the "ugly space" that brakes it.
    – fisehara
    Commented May 14, 2019 at 7:30
  • 4
    Came here in 2021 to be baffled about this. Thanks.
    – JHH
    Commented Nov 10, 2021 at 13:06
  • For what is worth, it also happens on debian bash with a PC (french) keyboard with [Alt gr] + space... Since [Alt gr] is necessary to produce the pipe on this keyboard, that happens quite often to me.
    – aka.nice
    Commented Feb 28, 2023 at 16:08
26

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

1
  • very weird behaviour
    – maoizm
    Commented Feb 7, 2023 at 9:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.