MacOS – Terminal gives :command not found, when typing too fast

bashcommand linekeyboardmacosterminal

I'm having the weirdest problem on my new MacBook pro, I had the same on the old one and I thought it might have something to do with that.

On my old MacBook Pro, whenever I used the pipe char in my Terminal followed by, let's say, grep I'd get a command not found. If I then just typed grep in plain in the Terminal I'd get the standard output.

Later I discovered that the problem only occurred when I typed in the command fast:

Lets say I wanted to use tee to inherit something in a few text files. From another Terminal I'd do:

echo "-r base.txt" | tee -a development.txt texting.txt production.txt

I know this command and I'm able to type it all in ~3 seconds. It gives me:

-bash: tee: command not found

Now if I try the exact same command but really take my time typing it, lets say I use 20 seconds on typing it, then I get:

-r base.txt

This is a confirmation that the command was executed properly.

I believed something was wrong with my old MacBook. Four months ago when I bought a new Mac it was exactly the same.

I then tried to do a fresh install. I deleted the hard drive and installed macOS from scratch. The same thing still occurs.

Has anyone else experienced this problem? If so, do you have a fix?

I also tried to install another Terminal like iTerminal2, I think that's what it's called, but with the exact same problem

Best Answer

Your problem is actually not Terminal.app specific.

The problem is more caused by you being slow on the keys than fast actually. When you type the | (pipe) character you need to hold down the Alt-key. When you're typing fast, you're actually too slow in releasing the Alt-key.

This means that you're not actually typing a space before the next command. You're pressing Alt-Space which gives you a "non-breaking space" - which is not the same as a space, but it looks that way in the Terminal.

The "non-breaking" space is not seen by your shell as a command delimiter, but instead a part of a command or file name. And therefore you get the error that no such file or directory exists.

To solve the problem - just remember to lift your finger from the alt key before typing space.

Alternatively you can change your keyboard mapping so that Alt-Space produces an ordinary space. You can find a guide to doing that here:

https://superuser.com/questions/78245/how-to-disable-the-option-space-key-combination-for-non-breaking-spaces