我正在编写一个简单的基本 bash 脚本(以 开头#! /bin/bash,文件格式为.sh)并且我正在尝试使进度条正常工作:
#!/bin/bash
echo "You are running in LXDE mode. Answer 'yes' or 'no' on the following question to continue (or not) in LXDE mode."
zenity --question --text='Do you want to continue in LXDE mode?' --ok-label=Yes --cancel-label=No
echo "Please enter your username and password to continue because the following command needs root privileges."
zenity --password --username
echo "Please enter today's date:"
zenity --calendar --text="Please enter today's date:"
echo "Please enter your name:"
zenity --entry --text='Please enter your name on the text entry below:'
echo "Analyzing data..."
zenity --info --text='Now begin analyzing data. If it takes more than 40 seconds, click on "Cancel".'
zenity --progress --title='Analyzing data...' --pulsate
Run Code Online (Sandbox Code Playgroud)
我试图让它从 0% 移动到 100%,但什么也没发生。它一直停留在 0%。我还尝试通过使用该--pulsate选项使其脉动,但仍为 0% 什么都不做。
谁能帮帮我吗?任何帮助,将不胜感激。
该Zenity文档有一个小的代码段应该做你寻找什么。
#!/bin/sh
(
echo "10" ; sleep 1
echo "# Updating mail logs" ; sleep 1
echo "20" ; sleep 1
echo "# Resetting cron jobs" ; sleep 1
echo "50" ; sleep 1
echo "This line will just be ignored" ; sleep 1
echo "75" ; sleep 1
echo "# Rebooting system" ; sleep 1
echo "100" ; sleep 1
) |
zenity --progress \
--title="Update System Logs" \
--text="Scanning mail logs..." \
--percentage=0
if [ "$?" = -1 ] ; then
zenity --error \
--text="Update canceled."
fi
Run Code Online (Sandbox Code Playgroud)
首先尝试只复制那里的代码并运行它并确认它按预期工作,然后修改以在适当的地方添加代码。
如果您的进度条停留在零,请确保绕过脚本中可能挂起并让您认为它确实在工作的任何部分!
编辑:正如下面的答案中所述,它不起作用的原因是因为 zenity 期望进度与其相呼应,就像在代码示例中一样。
| 归档时间: |
|
| 查看次数: |
10578 次 |
| 最近记录: |