PDA

View Full Version : Less not working in terminal window



Aborghgr
9th February 2007, 10:29 AM
Hi all,

My problem is this: 'less' doesn't function properly when executed in
any X terminal application. I tried konsole, gnome-terminal and xterm,
all with the same result: a blank window with two lines at the bottom:


ESC]2;myname@mymachine:/home/myname/^GESC]1;mymachine^G textfilename (END)


When I log into a non-X session however, less works just fine. 'More'
and 'nano' work without problems as well, X-terminal or not. Any idea
on what might cause this? I'm using FC6.

RupertPupkin
9th February 2007, 05:00 PM
That's strange. I wonder if it's something in your ~/.bash_profile that isn't being being sourced in the terminal program. When you login via the console, your ~/.bash_profile gets sourced. But most terminal programs don't run a login shell by default. To test this, run 'xterm -ls', which will run xterm as a login shell and source your ~/.bash_profile, and then try the 'less' command in that. If that works, then you need to modify the settings in konsole and gnome-terminal to run a login shell.

Aborghgr
15th February 2007, 02:46 PM
That's strange. I wonder if it's something in your ~/.bash_profile that isn't being being sourced in the terminal program. When you login via the console, your ~/.bash_profile gets sourced. But most terminal programs don't run a login shell by default. To test this, run 'xterm -ls', which will run xterm as a login shell and source your ~/.bash_profile, and then try the 'less' command in that. If that works, then you need to modify the settings in konsole and gnome-terminal to run a login shell.

Well, we use tcsh by default here, not bash. So I ran 'xterm -ls', and inside that xterm ran 'bash', with the same result. Same when running "tcsh" inside the xterm, and inside the bash session. Then I started playing some with the Session options in konsole, and I noticed that less worked in 2 types of sessions: the "Linux Console", and the "Screen Session", but not in the default "Shell". I then looked inside "Settings->Configure Konsole" to figure out what was the difference between the sessions, and there were two parameters defining the sessions: "$TERM" and "Execute". "Shell" has $TERM=xterm and no additional commands to execute, "Screen Sessions" has $TERM=xterm and Execute=screen, and "Linux Console" has $TERM=linux and Execute=bash.
So when I run "xterm -e screen", I get a bare xterm within which less works. I can't seem to find a "linux" terminal on the command line, though I can enter the settings for "Linux Console" in the default "Shell" entry. This means I've got a working solution for my problem, though I still don't get why it doesn't work in the default xterm, and why it does when running screen. You think there might be something wrong with my .tcshrc file (and my .bash_profile, which is a bashified version of the same)? I'll see if I can find something in it regarding the xterm.

Aborghgr
16th February 2007, 01:02 PM
Ok, been playing with the .tcshrc file a bit, and I located the problem: it's within the following block of code:



if ( $term == "xterm" ) then
rs
rs
alias cwdcmd 'echo -n "\033]2;${USER}@${HOST}:$cwd\007\033]1;${HOST}\007"'
cwdcmd
else
unalias cwdcmd
endif


Apparently "cwdcmd" sets the xterm/konsole header to user@host:homedir, which is also what appears
when less is called, instead of the contents of the file opened with less. What I'd like to know is why this
command is called when less opens a file? It seems to me that it is called once when the terminal is
opened. Does less behave like a new xterm session for some reason?

djdeccy
17th April 2008, 11:01 PM
Hi there, did you ever figure out what was going on here?
I'm facing the same issue myself.

I've narrowed it down to these lines in my .cshrc:
if ( $TERM == "xterm") then
alias cwdcmd 'echo -n "\033]0;${USER}@${HOST}:$cwd\007"'
cwdcmd
endif

I'm using tcsh version 6.14.00 and Less version 382