在实际使用GUI对话之前,请考虑使用控制台提示。很多时候你可以用简单的“y / n?”提示,在bash中你通过
read command实现..
read -p "Do something? ";
if [ $REPLY == "y" ]; then
echo yay;
fi
如果控制台提示只是不会剪切它,Zenity是真的easy to use,例如:
zenity --error --text="Testing..."
zenity --question --text="Continue?"
这只适用于Linux / Gnome(或者更确切地说,它只会在这样的系统上默认安装)。读取方法将在几乎任何平台(包括无头机器,或通过SSH)
如果你需要更复杂的读取或Zenity提供,“改为C”是真正的最好的方法(虽然我建议Python / Ruby over C这样的shell脚本替换任务)
I want to do simple interface for some strange game,the progress bar for health or something is the example for what I want. Variable “HEALTH” is 34,so make progress bar filled in 34/100
作为命令行脚本,它将使用Python:
$ export HEALTH=34
$ python -c "import os; print '*' * int(os.environ.get('HEALTH',0))"
**********************************
或者标准化1和78之间的值(所以你不能在标准终端大小上包装):
$ python -c "import os; print '*' * int((int(os.environ.get('HEALTH',0)) / 100.0) * 78)"
#!/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
正如我之前说的,如果Zenity不能做你所需要的,看看在Python / Ruby / Perl / C / etc中把你的游戏作为一个“正确”脚本,因为它听起来像你在推动shell的边界-script可以做..