Various environments and weird less behaviour

2

I am playing with I/O redirection and have problem with less behaving differently in two environments. Both environments are Solaris-based and are of the same version.

I am executing program in two environments like this:

env 1:

script </dev/pts/1 >&/dev/pts/1 (/dev/pts/1 is my SSH session terminal)

env 2:

script </dev/console >&/dev/console (/dev/console is Solaris main console)

Script looks like this:

#!/bin/bash

exec 4>>/tmp/script.log
export PS4='[\D{%FT%TZ}] $(tty): ${BASH_SOURCE}:${LINENO}:    ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
export BASH_XTRACEFD=4
set -o xtrace

export TERM=xterm-color

file=/path/to/big/file
less -MQEX ${file}
read

In env 1 everything works correctly, I am able to control less and scroll up/down, quit etc. In env 2, the less only displays first part of file and quits without being able to scroll up/down or manipulate within the file. env 2 is a script, which is run from SMF manifest. The things I have tried:

  1. playing around with various bash options (interactive vs non-interactive), but it doesn't have any influence on this. In both environments I have the following bash options ($-) set "hxB".

  2. setting different TERM types didn't affect less behaviour. I have tried "xterm", "vt100" and "vt220".

I am not sure what else should I try or where to look. How should I proceed with the debugging of less behavior? Any hints are appreciated.

lessbehaviour

Posted 2015-10-19T19:41:36.633

Reputation: 21

What is the value of $TERM in the console? It might not be capable to do what you want. – glenn jackman – 2015-10-19T20:16:51.033

xterm-color. It works in env 1, but not in env 2. – lessbehaviour – 2015-10-19T20:25:49.440

Answers

0

If that is really a Solaris console, it is not compatible with xterm (or anything related to a VT100). VT100s use an escape sequence for scrolling which does interesting things with the Sun hardware.

Referring to the manual page for wscons, anything that is marked with "SUN" in the name in parenthesis is pretty much guaranteed to be a point of incompatibility. Like the VT100 scrolling controls, these are escape sequences not part of "ANSI X3.64" (long ago withdrawn, replaced by ECMA-48). The source of your problem is this one:

ESC[#r Set Scrolling (SUNSCRL)

Takes one parameter, n (default 0). Sets to n an internal register which determines how many lines the screen scrolls up when a line-feed function is performed with the cursor on the bottom line. A parameter of 2 or 3 introduces a small amount of jump when a scroll occurs. A parameter of 34 clears the screen rather than scrolling. The initial setting is 1 on reset.

A parameter of zero initiates wrap mode instead of scrolling. If a linefeed occurs on the bottom line during wrap mode, the cursor goes to the same character position in the top line of the screen. When a line feed occurs, the line that the cursor moves to is cleared and no scrolling occurs. ESC [ 1 r exits back to scroll mode.

For more information, see the description of the Line-feed (CTRL-J) control function above.

A VT100-style CSR (change scrolling region) takes two parameters, which are the starting and ending rows of the scrolling region.

Thomas Dickey

Posted 2015-10-19T19:41:36.633

Reputation: 6 891

Setting sun-color didn't help. What should be done? – lessbehaviour – 2015-10-19T21:03:39.253

I read this answer as saying "you can't do it" – glenn jackman – 2015-10-19T21:40:52.030

No... I think that if the problem is as I guessed, then OP could have applied the TERM setting in the wrong place (or did not reset the terminal modes on the console, leaving it in whatever half-done scrolling was started before) - something to check over. less should be able to cope with terminals lacking scrolling regions. – Thomas Dickey – 2015-10-19T21:54:24.343

Removing the line, which sets the terminal to xterm-color and trying again makes some changes. The terminal is started in dumb mode and less at least spits out "Termina not fully functional". I also tried to reset terminal with "reset" and "stty sane; tput rs1", but no avail. I also found out that I am not able to set terminal size as in env 1 (stty cols or stty rows does nothing). – lessbehaviour – 2015-10-20T05:47:31.047

In a quick check on Solaris 10, it seems that setting TERM to "sun" rather than "sun-color" works better. I tested with ded, and see problems with "sun-color".

– Thomas Dickey – 2015-10-20T13:39:35.790