Bad Escape Character Error after Installing Shell Integration

  • iTerm2 version: 3.4.2
  • OS version: macOS Catalina 10.15.7

com.googlecode.iterm2.plist

After installing shell integration and opening a new window, the following error appears:

Last login: Fri Dec  4 11:44:56 on ttys003
Bad escape character '/Users/roo/.iterm2_shell_integration.zsh'.
roo@kanga ~ %

It seems to originate from this line added in .zshrc:

test -e "${HOME}/.iterm2_shell_integration.zsh" && source "${HOME}/.iterm2_shell_integration.zsh"

Replacing that with source ~/.iterm2_shell_integration.zsh makes the error go away. Maybe some escape character inside ${HOME}/.iterm2_shell_integration.zsh is being flagged by test -e?