3

I've got very odd problem when I set export TERM=xterm-256color in ~/.bash_profile. When I try to run nano or emacs I get the following errors.

nano:

.rror opening terminal: xterm-256color

emacs:

 is not defined.type xterm-256color
If that is not the actual type of terminal you have,
use the Bourne shell command `TERM=... export TERM' (C-shell:
`setenv TERM ...') to specify the correct type.  It may be necessary
to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.

If I manually enter the following into the shell it works

export TERM=xterm-256color

I'm stumped.

tripleee
  • 175,061
  • 34
  • 275
  • 318
David Crayford
  • 571
  • 1
  • 3
  • 10
  • 1
    by default you have c shell from error message it seems. your might be changing the shell to bash after logging into the terminal? – SMA Nov 28 '14 at 12:37
  • Show actual lines from your bash profile and actual error messages. Format all code and messages as code. See [formatting help](http://stackoverflow.com/editing-help). Use the edit button to fix your question. – n. m. could be an AI Nov 28 '14 at 12:45
  • 2
    Well, this environment variable should be set by a terminal emulator which knows precisely what kind(s) of terminal emulation it supports – user3159253 Nov 28 '14 at 12:50
  • 2
    Why are you trying to set `TERM` manually in the first place. That generally is *not* the correct thing to do. – Etan Reisner Nov 28 '14 at 13:24

1 Answers1

7

Looks like you have DOS line feeds in your .bash_profile. Don't edit files on Windows, and/or use a proper tool to copy them to your Linux system.

Better yet, get rid of Windows.

In more detail, you probably can't see it, but the erroneous line actually reads

export TERM=xterm-256color^M

where ^M is a literal DOS carriage return.

Like @EtanReisner mentions in a comment, you should not be hard-coding this value in your login files, anyway. Linux tries very hard to set it to a sane value depending on things like which terminal you are actually using and how you are connected. At most, you might want to override a particular value which the login process often chooses but which is not to your liking. Let's say you want to change to xterm-256color iff the value is xterm:

case $TERM in xterm) TERM=xterm-256color;; esac

This is not a programming question and yet an extremely common question on StackOverflow. Please google before asking.

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • 1
    Thanks, that was the problem. I was using the slickedit editor on Windows over sftp. Luckily slickedit supports all combinations of line feeds when saving a file so it was easily fixed. Many thanks. – David Crayford Mar 09 '15 at 12:20