我有一个在Debian上运行的shell脚本。它包含许多功能和条件。有一个菜单,用户可以选择不同的选项,并显示不同的输出。用户可以随时返回主菜单并再次选择一些选项,然后将显示另一个输出。当然每次用“清除”清除屏幕。
然而,当输出包含太多行时,我将能够向上滚动一点,但它将停止,我将无法一直滚动到我需要看到的第一行。能够用摩丝轮向上滚动是我想要的行为之王......
看起来问题来自xterm窗口,因为它与普通终端一样好。然而xterm很好,因为我可以设置高度和宽度,以及更改颜色......
是否有办法从脚本本身增加此限制,因为我无权在Debian环境中更改任何内容...
我读到有些人实际将整个脚本管道化为“少”,我试过,问题是我不能再使用菜单了......
请在下面找到用于运行主要脚本的第一个脚本:
xterm -fg ivory -bg darkblue -fn 8x13bold -geometry 76x110+1700+0 -T "QC CHECK" -e /tests/SCRIPTS/QC/qc.sh
以下是我的脚本的一些示例,但它包含更多内容:
#!/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
正如你所看到的,我有许多功能,而且许多被调用的变量是一些“回声”,这使我很难在有太多行的情况下向上滚动,并且用户也可以向上和向下滚动看到一切,选择和行动。
答案 0 :(得分:1)
通过less
或more
管道输出。有选项(hot keys)可以前进,后退,搜索等。
答案 1 :(得分:0)
我找不到滚动输出长度的方法,所以我所做的是一个循环,逐渐增加0.1 $ {maxnoise}的值(带有输出行数的条件)因为这个变量实际上是调节输出有多大的变量。这样做很好,所以我认为我的问题得到了解答。