Pulimon Pulimon - 6 months ago 23
Bash Question

Issues with newline character while using ansi-term in emacs

I am trying to use ansi-term in emacs (configured to tcsh shell). I see some issues with newline characters being displayed. If I try the following from the terminal (ansi-term), I get the correct output:

myterm > echo "Line1"; echo "Line2"; echo "Line3";
Line1
Line2
Line3
myterm >


But if I try putting the same lines in a shell script and try to execute the script from ansi-term, I get a wrong output

Script: (test)

#!/usr/bin/env tcsh
echo "Line1"; echo "Line2"; echo "Line3";


Running the script (test):

myterm > ./test
Line1
Line2
Line3
myterm >


Note: /usr/bin/env tcsh does point to the correct shell (its the same shell that I used while invoking ansi-term). Also executing the script from gnome-terminal also displays the correct output.
I have also tried setting the following variables but it did not solve my issues:

(set-terminal-coding-system 'utf-8-unix)
(setq default-process-coding-system '((utf-8-unix . utf-8-unix)))

Answer

You need to stty onlcr in your script.

I will leave the forensics of exactly where this is being unset in the tcsh environment as a exercise for the questioner ;)

Comments