1

我想在whiptail界面中显示实时变量的值。我像这样的增量变量=

#!/bin/bash

i=1

while test $i -ne 51
do 

    echo "$i" 

    i=$(($i + 1)) #icremente i

done

如何在带有whiptail的GUI中显示实时值?

4

1 回答 1

1

The usual way would be to pipe the results to a --gauge option (gauge widget). whiptail's manual page lists that.

whiptail implements a subset of dialog's options; if you were using dialog, one might suggest displaying successive --infobox messages (also part of the subset), but the effect with xterm may not be good -- too much flashing (dialog cancels the switch to xterm's alternate screen which many terminal descriptions use).

Here is a sample using the latter:

#! /bin/sh

: ${PROG=whiptail}

left=10
unit="seconds"
while test $left != 0
do

$PROG --title "INFO BOX" "$@" \
        --infobox "Hi, this is $left $unit to read this..." 10 52
left=`expr $left - 1`
test $left = 1 && unit="second"
sleep 1
done

If you were to use that in xterm without disabling the alternate screen switching (e.g., setting the resource *titeInhibit:false) it would not work well, of course.

于 2015-04-17T23:03:56.070 回答