When running M-x shell I get strange additional characters.

It looks like this,

enter image description here

I should look similar to how it does in the terminal,

enter image description here

I am very new to Emacs. Hopefully there is a simple fix.

I am running Fedora 25 and GNU Emacs 25.1.1


The problem is in your shell configuration. It's sending escape sequences to color parts of the prompt, to set the terminal sequence, etc. But the terminal of M-x shell is a very basic one that doesn't understand these escape sequences. You need to turn off all these features.

The basic way to detect the terminal capabilities is to query the TERM variable. Under M-x shell, its value is dumb. Turn off all prompt formatting and other similar configuration when $TERM is dumb.

For example, if your shell is bash, use something like in your .bashrc:

if [[ "$TERM" == "dumb" ]]; then
  # No terminal escape sequences, only prompt escapes
  PS1='\u at \h in \w\n\$ '
  # Assuming a rich terminal, using terminal escape sequences
  PS1='\e]2;\w\a\e]1;\W\a\u at \h in \w\n\$ '
  • M-x eshell works great for me. Thanks
    – Shane G
    Sep 20 '16 at 20:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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