shell

Shell script output, how to scroll up?


I have a shell script that runs on Debian. It contains lots of functions and conditions. There is a menu and the user may choose different options and different outputs will be displayed. The user can always go back to the main menu and choose again some options then another output will be displayed. Of course each time the screen is cleared with "clear".

However when then output contains too many lines, I will be able to scroll up a little bit, but it will stop and I won't be able to scroll all the way to the first line I need to see. Being able to scroll up with the mousse wheel is the king of behavior I would like...

It looks like the problem comes from the xterm window, because it is fine with the normal terminal. However xterm is nice because I can setup the height and the width, as well as changing the colors...

Is there a way to increase this limitation from the script itself as I won't have the permission to change anything in the Debian environment...

I read that some people actually pipe the entire script to "less", I tried that, the problem is that I can't use the menu anymore...

Please find below the first script that is used to run the main one:

xterm -fg ivory -bg darkblue -fn 8x13bold -geometry 76x110+1700+0 -T "QC CHECK" -e /tests/SCRIPTS/QC/qc.sh

Below is a little sample of my script, but, it contains much more:

#!/bin/sh
stty erase ^H

function water
{
clear
echo -e "Current Survey   : ${proj}"
echo -e "Current Sequence : ${seq}"
echo -e ""
echo -e "           [ Trace QC Water Column ]"
echo -e ""
if [ $mincable -eq $maxcable ]
then
echo -e "           Cable checked   : $maxcable"
else
echo -e "           Cables checked  : ${mincable}-${maxcable}"
fi
echo -e "           Max noise level : ${maxnoise}uB"
if [ ${skiptrace} -eq 0 ]
echo -e "           Traces skipped  : ${skiptrace}"
else
echo -e "           Traces skipped  : 1-${skiptrace}"
fi
echo -e ""
#############
water=`awk --field-separator=";" '($4>'$maxnoise') {print int(a=(($1-1)/'$nb_traces')+1) " " ($1-((int(a)-1)*'$nb_traces')) " " $4}' ${seq}_TraceAverages.txt | grep -v "USER_AVRMS_WC1" | grep -v "R32" | awk '{printf $1 " "  $2 " " ("%*.*f\n"), 1, 2, $3}' | awk '($2>'$skiptrace')&&($1>='$mincable')&&($1<='$maxcable') {print $1 " - " $2 " - " $3}' | awk '{printf("%16s%6s%8s%6s%10s\n"), $1, $2, $3, $4, $5}' | awk '(NR>1) && (old != $1) {printf("%65s\n"), "'$sep_cable'"} {print; old=$1}'`
#############
count_water=`awk --field-separator=";" '($4>'$maxnoise') {print int(a=(($1-1)/'$nb_traces')+1) " " (b=($1-((int(a)-1)*'$nb_traces'))) " " $3}' ${seq}_TraceAverages.txt | grep -v "USER_AVRMS_WC1" | grep -v "R32" | awk '($2>'$skiptrace')&&($1>='$mincable')&&($1<='$maxcable') {print $3}' | wc -l`
#############
echo -e "           ------------------------------------------------------"
echo -e ""
echo -e "             Cable   -    Trace    -     RMS_WC"
echo -e ""
echo -e "           ------------------------------------------------------"
echo -e ""
if [ $count_water -ge 1 ]
then
echo -e "$water"
else
setterm -term linux -back red -fore white
echo -e "           Wow! No traces? Maybe decrease your values..."
setterm -term linux -default
fi
echo -e ""
setterm -term linux -back blue -fore white
echo -e "           RMS_WC > ${maxnoise}uB = $count_water"
setterm -term linux -default
echo -e ""
echo -e "           ------------------------------------------------------"
echo -e ""
}

    # check for latest project in /tests
proj_temp
    # if config file is missing go to config menu
if [ ! -e /tests/$proj/SCRIPTS/QC/config ]
then
config
fi
    # force choice=1 and config_ok=1 to return to main menu when loop has run once (no problem when more than one)
choice=1
config_ok=1
while :
do
    # do it all
if [ ${choice} -eq 1 2>/dev/null ]
then
choice=X
config_ok=1
    # read configuration file
readconfig
main
    # config menu and help
    if [ ${seq} = "c" ]
    then
config
    elif [ ${seq} = "h" ]
    then
help
    elif [ ${seq} = "q" ]
    then
clear
setterm -term linux -back magenta -fore white
echo ""
echo -e "\t Try me next time :*"
sleep 0.65
exit
    fi
    # config_ok=1 when configuration is done, meaning user returns to main menu after exiting config menu
    if [ ${config_ok} -eq 1 ]
    then
cd $input_dir
    # check if file for requested sequence is valid
testline
    # this function updates the awk script for signal QC check
awkscript
doall
choice
    fi
    # let the user choose what QC is wanted
elif [ ${choice} -eq 2 2>/dev/null ]
then
choice=X
    # initialize values so that user can choose its own
init
menu
option
fi
    case ${menu} in
            1) deep
               choice ;;
            2) water
               choice ;;
            3) awkscript
               signal
               choice ;;
            4) readconfig
               awkscript
               doall
               choice ;;
    esac
if [ ${choice} = "q" 2>/dev/null ]
then
exit
fi
done

As you can see I have many functions and many variables that are called is some "echo" which makes it hard for me to scroll up when there is too many lines, and, the user got also to scroll up and down to see everything and to choose and action.


Solution

  • I could not find a way to scroll through the length of my output so what I did is a loop that is gradually increasing by increments of 0.1 the value of ${maxnoise} (with a condition on the number of line output) because this variable is actually the one conditioning how big is the output. It works fine this way so I consider my question answered.