如何在进度条和进度条上显示不同的消息?

时间:2016-12-06 07:17:24

标签: bash shell scripting whiptail

我正在尝试使用“whiptail”向用户显示进度,同时删除一些RPM。使用

{
 echo 25
 yum remove package_name
 echo 50
 yum remove package_name
 echo 75 
 yum remove package_name
 echo 100
 sleep 1

} | whiptail --gauge "Removing RPM's" 6 60 0*

This is how it looks like

我想要的是显示消息“正在删除package_name”以及进度条,就像redhat安装包时一样 something like this 我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:2)

Whiptail使用奇怪的语法来更新仪表文本。看看下面的脚本:

#!/bin/bash
{
    sleep 0.5
    echo -e "XXX\n0\nyum remove package_0... \nXXX"
    sleep 2
    echo -e "XXX\n25\nyum remove package_0... Done.\nXXX"
    sleep 0.5

    echo -e "XXX\n25\nyum remove package_1... \nXXX"
    sleep 2
    echo -e "XXX\n50\nyum remove package_1... Done.\nXXX"
    sleep 0.5

    echo -e "XXX\n50\nyum remove package_2... \nXXX"
    sleep 2
    echo -e "XXX\n75\nyum remove package_2... Done.\nXXX"
    sleep 0.5

    echo -e "XXX\n75\nyum remove package_3... \nXXX"
    sleep 2
    echo -e "XXX\n100\nyum remove package_3... Done.\nXXX"
    sleep 1
} |whiptail --title "Yum Removal" --gauge "Please wait while installing" 6 60 0

此处,关键部分是echo -n "XXX\n<new percent>\n<new_gauge_text>\nXXX"。 whiptail使用XXX字符串表示对显示的修改。