Pul*_*mon 6 emacs shell terminal tcsh ansi-term
我试图在emacs中使用ansi-term(配置为tcsh shell).我看到显示换行符的一些问题.如果我从终端(ansi-term)尝试以下操作,我会得到正确的输出:
myterm > echo "Line1"; echo "Line2"; echo "Line3";
Line1
Line2
Line3
myterm >
Run Code Online (Sandbox Code Playgroud)
但是如果我尝试在shell脚本中添加相同的行并尝试从ansi-term执行脚本,则输出错误
脚本:(测试)
#!/usr/bin/env tcsh
echo "Line1"; echo "Line2"; echo "Line3";
Run Code Online (Sandbox Code Playgroud)
运行脚本(测试):
myterm > ./test
Line1
Line2
Line3
myterm >
Run Code Online (Sandbox Code Playgroud)
注意:/ usr/bin/env tcsh指向正确的shell(它与我在调用ansi-term时使用的shell相同).从gnome-terminal执行脚本也会显示正确的输出.我也试过设置以下变量,但它没有解决我的问题:
(set-terminal-coding-system 'utf-8-unix)
(setq default-process-coding-system '((utf-8-unix . utf-8-unix)))
Run Code Online (Sandbox Code Playgroud)
Nia*_*ove 15
如果stty onlcr在脚本中设置,则会获得所需的行为.
翻译该命令为一个英语可能会说:
小号等的TTY到ø安输出Ñ EW 升 INE作为Ç arriage- - [R E打开和换行.
当然这是一种解决方法,因为默认情况下应该设置此选项.我可以从stty -a你的评论的输出中看出它是在你的ansi-term中运行的tcsh中设置的.我怀疑ansi-term和你的shell脚本表现不同的一个可能原因是由于term.el中的以下行
(apply 'start-process name buffer
"/bin/sh" "-c"
(format "stty -nl echo rows %d columns %d sane 2>/dev/null;
if [ $1 = .. ]; then shift; fi; exec \"$@\""
term-height term-width)
".."
command switches)))
Run Code Online (Sandbox Code Playgroud)
stty上面的命令实际上设置了onlcr两次,因为
复合选项-nl转换为 icrnl -inlcr -igncr onlcr -ocrnl -onlret
并且sane选项转换为
cread -ignbrk brkint -inlcr -igncr icrnl -iutf8 -ixoff -iuclc -ixany imaxbel opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0 isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke
另一个可能的原因:对于非登录shell tcsh的将只读取/etc/csh.cshrc,要么~/.tcshrc或~/.cshrc启动时,但登录shell读取了一些其他的文件,包括/etc/csh.login ~/.history或价值$histfile-你应该参考手册页的全部细节,包括准确它读取事物的顺序.