less -RF problem

Hello,

I see some annoying behavior for GNU "less" on my machine:

If I type

less -F 4_lines_file

in the shell the expected behavior would be similar to "cat" behavior i.e. if the file has less lines than the screen height allows, then less just displays the contents of the file and then exits. Instead, what happens is that less doesn't display anything!

When the file is larger than the screen height, then less -F behaves correctly i.e. it displays the file in a pager session.

The interesting thing is that less -F behaves perfectly well inside of a GNU screen session. I tried setting the TERM environment variable to "screen" while on a normal login shell, but that didn't help.

Any clues what might be leading to this behavior?

Here is a command line example of the aforementioned problem (normal shell session):

neked@neked-ubuntu-wks:~/misc$ cat > 4_lines_file << EOF
> first line
> second line
> third line
> fourth line
> EOF
neked@neked-ubuntu-wks:~/misc$ less -F 4_lines_file
neked@neked-ubuntu-wks:~/misc$

Inside of a screen session:

neked@neked-ubuntu-wks:~/misc$ less -F 4_lines_file
first line
second line
third line
fourth line
neked@neked-ubuntu-wks:~/misc$

less is intended as an interactive program that uses advanced terminal features. It does its best to avoid modifying the contents of the terminal altogether; what you see happening is not nothing, but it in fact clearing the terminal, displaying the lines, instantly quitting, and restoring the contents of the terminal as most any curses-based program will do. It does seem a pretty useless commandline switch. I wonder if it predates less' use of curses.

I would guess screen's terminal emulation doesn't support any sort of content-restore feature, so less simply can't. To avoid it screwing with the terminal so much, try the --no-init aka -X option.

Nice, that worked pretty well:

neked@neked-ubuntu-wks:~/misc$ less --no-init -RF 4_lines_file
first line
second line
third line
fourth line

From the less man page:

       -X or --no-init
              Disables sending the termcap initialization and deinitialization
              strings to the terminal.  This is  sometimes  desirable  if  the
              deinitialization  string does something unnecessary, like clear-
              ing the screen.

I wonder if we can configure how the terminal responds to the "termcap initialization and deinitialization" strings.

Thanks for your reply!