如何为linux shell设置TERM环境variables

当我在〜/ .bash_profile中设置export TERM = xterm-256color时,我遇到了很奇怪的问题。 当我尝试运行nano或emacs时,出现以下错误。

纳米:

.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. 

如果我手动input以下内容到它的工作

 export TERM=xterm-256color 

我很难过

看起来你的.bash_profile有DOS行。 不要在Windows上编辑文件,和/或使用适当的工具将它们复制到您的Linux系统。

更好的是,摆脱Windows。

更详细地说,你可能看不到它,但是错误的行实际上是读取的

 export TERM=xterm-256color^M 

其中^M是一个文字DOS回车。

就像@EtanReisner在评论中提到的那样,不管怎样,你不应该在登录文件中硬编码这个值。 Linux很努力的将其设置为一个合理的值, 取决于你正在使用哪个终端以及你是如何连接的。 最多的情况下,您可能需要重写登录过程中经常选择的特定值,但这不符合您的喜好。 假设您想要更改为xterm-256color如果值为xterm

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

这不是一个编程问题,而是一个关于StackOverflow的非常常见的问题。 请问谷歌之前。