This seems like a common issue: you paste a simple command from somewhere into the terminal and it's not being understood by a shell:

$ echo test
$ zsh: command not found: echo test

The reason is because the words are separated with NBSP instead of space. Can the shell be instructed to consider NBSP a whitespace character?

  • 2
    Sounds that the problem here is that your clipboard contains the wrong character, not that zsh is not breaking on the non-breaking space. Rather than changing the syntax of the shell, a better work around (for that issue that is not in zsh) could be to replace those nbsps with spcs (which they were meant to be in the first place) after pasting. Jul 2, 2020 at 7:32
  • @Eugene Yarmash I cannot reproduce this at all. What terminal and OS do you use? Jul 2, 2020 at 8:54
  • @Marlon See the linked page for some methods. For example, in macOS you can type ⌥ Option + Space to get an NBSP character. This can be reproduced in bash or zsh. Jul 2, 2020 at 9:07
  • 1
    @StéphaneChazelas agreed, it's the wrong character, but when copying and pasting from some sites' tutorials "out there" it can be a problem not of the learner's making.
    – roaima
    Jul 2, 2020 at 12:25
  • @Eugene Yarmash I know how to produce a non-breaking space; that’s not what I meant. What I meant is that when I copy-paste text containing an nbsp into my terminal, it works just fine in Zsh for me. I made an HTML page that contains echo test, then copy-pasted from Safari into Terminal.app and it works the exact same as if I had typed echo test. Jul 2, 2020 at 21:29

1 Answer 1


Assuming your terminal supports bracketed paste, you can redefine the zsh paste widget to substitute non-breaking spaces. For example:

    bracketed-paste-subst() {                  
        local content
        zle .bracketed-paste -N content
        LBUFFER+="${content//$'\u00a0'/ }" 
        zle -f yank 2> /dev/null
    zle -N bracketed-paste-subst
    bindkey "^[[200~" bracketed-paste-subst

In theory, you can add non-breaking space to the IFS variable to have it be treated as a word separator but I'm not sure that works for non-ASCII and it isn't a good idea to do that anyway.

  • 1
    $IFS is only involved in read, unquoted $=var and command substitution, not in the shell grammar tokenisation. Sep 26, 2020 at 16:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .