我發現了一個很棒的小程序,可以讓我將用戶友好的GUI添加到我的Bash腳本中;BASH腳本:whiptail文件選擇
鞭尾
然而whiptail man page是不是所有的樂於助人,不提供任何例子。做了一些谷歌搜索後,我明白瞭如何創建一個簡單的是/否菜單使用鞭尾:
#! /bin/bash
# http://archives.seul.org/seul/project/Feb-1998/msg00069.html
if (whiptail --title "PPP Configuration" --backtitle "Welcome to SEUL" --yesno "
Do you want to configure your PPP connection?" 10 40)
then
echo -e "\nWell, you better get busy!\n"
elif (whiptail --title "PPP Configuration" --backtitle "Welcome to
SEUL" --yesno " Are you sure?" 7 40)
then
echo -e "\nGood, because I can't do that yet!\n"
else
echo -e "\nToo bad, I can't do that yet\n"
fi
但我真的想用鞭尾,以取代一些舊的代碼,我有幾個建一個文件選擇菜單不同的備份/恢復的bash腳本我有:
#!/bin/bash
#This script allows you to select a file ending in the .tgz extension (in the current directory)
echo "Please Select the RESTORE FILE you would like to restore: "
select RESTOREFILE in *.tgz; do
break #Nothing
done
echo "The Restore File you selected was: ${RESTOREFILE}"
我認爲這必須通過鞭尾的「--menu」選項來完成的,但我不知道如何做呢? 任何指針? 或者你能指點我一些whiptail例子的方向嗎?
我已經對我的答案(八進制轉換公式)做了一些小改動。 – 2009-10-16 22:11:56