1

用这个例子

#!/bin/sh
#A gauge Box example with dialog
(
c=10
while [ $c -ne 110 ]
    do
        echo $c
        echo "###"
        echo "$c %"
        echo "###"
        ((c+=10))
        sleep 1
done
) |
dialog --title "A Test Gauge With dialog" --gauge "Please wait ...." 10 60 0

我可以做一个量规。

我怎样才能用两个或多个仪表进行对话?

如同

[##   20% ]
[#### 40% ]
4

2 回答 2

3

试试看--mixedgauge

#! /bin/sh
# $Id: mixedgauge,v 1.4 2007/02/26 23:10:30 tom Exp $
: ${DIALOG=dialog}
background="An Example of --mixedgauge usage"

for i in 5 10 20 30 40 50 60 70 80 90 100
do
$DIALOG --backtitle "$background" \
        --title "Mixed gauge demonstration" \
        --mixedgauge "This is a prompt message,\nand this is the second line." \
                0 0 33 \
                "Process one"   "0" \
                "Process two"   "1" \
                "Process three" "2" \
                "Process four"  "3" \
                ""              "8" \
                "Process five"  "5" \
                "Process six"   "6" \
                "Process seven" "7" \
                "Process eight" "4" \
                "Process nine"  "-$i"
# break
sleep 1 
done

通过https://github.com/Archivists/ltfs-console/blob/master/samples/mixedgauge找到

于 2013-05-21T15:57:15.270 回答
1

发布完整的 bash 脚本,演示监视两个后台任务,因为它似乎在其他任何地方都不容易找到。

#!/bin/bash
[ -n "$DEBUG" ] && set -x

TASK[0]=0
export TASK

task1() {
    file="/tmp/task1_progress"; echo 0 > $file
    for i in $(seq 0 10 100); do echo $i > $file; sleep 1; done
}

task2() {
    file="/tmp/task2_progress"; echo 0 > $file
    for i in $(seq 0 10 100); do echo $i > $file; sleep 2; done
}

task1 & task2 &

unset TIME_TO_FINISH PROGRESS STATUS
while /bin/true;
do
    unset TASKS
    for i in 1 2;
    do
        PROGRESS[$i]=$(cat /tmp/task${i}_progress)
        if [ ${PROGRESS[$i]} -eq 100 ];
        then
            STATUS[$i]=0
        else
            STATUS[$i]=-${PROGRESS[$i]}
        fi

        TASKS+=("Task $i" "${STATUS[$i]}")
    done

    # 0: success
    # 1: failed
    # 2: passed
    # 3: completed
    # 4: checked
    # 5: done
    # 6: skipped
    # 7: in progress
    # -X: 0-100, progress of process
    dialog \
        --title "Mixed gauge demonstration" \
        --backtitle "Backtitle" \
        --mixedgauge "This is a prompt message,\nand this is the second line." \
            0 0 $(($((${PROGRESS[1]}+${PROGRESS[2]}))/2)) \
            "${TASKS[@]}"

    I=0
    for a in 1 2; do [ ${PROGRESS[$a]} -ge 100 ] && I=$((I+1)); done

    [ $I -eq 2 ] && break
    sleep 1
done
echo waiting
wait

set +x
于 2015-10-08T09:58:31.510 回答