[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: using less in a bash script, screen blanking, alternate screen



On 2013-09-08 09:53 +0200, Zenaan Harkness wrote:

> OK, I have the following script (reduced, just enough to demonstrate
> the problem):
>
> --- test.sh ---
> #!/bin/bash
> cmd="apt-cache search debian-installer | sort | egrep --color=always
> -i debian-installer"
> #tput nrrmc # line 3
> #less -REf <($cmd) # line 4
> less -REf <(bash -c "$cmd") # line 5
> #less -REf <(tput nrrmc; bash -c "$cmd") # line 6
> #less -REf <(bash -c "tput nrrmc; $cmd") # line 7
> ---
>
> I am running this script in a plan xterm (no embedded screen session),
> bash shell.
>
> When I manually run lines 2 then 5 in xterm, I get expected output in
> my terminal.
>
> When I run test.sh from xterm, I get a blank screen, followed by
> return to the xterm, as though the script didn't do anything! I would
> like to understand why.

It is due to xterm's "alternate screen" feature (see the xterm manpage
for details).  You may want to use less' "-X" option to prevent it from
using the alternate screen.

Cheers,
       Sven


Reply to: