|
|
This document is available in: English Castellano ChineseGB Deutsch Francais Italiano Nederlands Russian Turkce |
by Katja and Guido Socher <katja(at)linuxfocusorg, %20guido(at)linuxfocus.org> About the authors: Katja 是LinuxFocus的德国编辑. 她喜欢Tux, 电影, 摄影和大海. 这里是她的主页. |
摘要:
Xdialog和dialog是两种能使你的shell脚本具备图形用户界面(GUI)的工具.
你需要具备一些shell编程知识才能看懂这篇文章. 你可以看我们的Shell
Programming这篇文章来学一些shell编程的基础知识.
bash
Xdialog --yesno "Do you want to learn more about Xdialog?" 0 0;\
case $? in
0)
echo "Result: Yes chosen.";;
1)
echo "Result: No chosen.";;
255)
echo "ESC pressed.";;
esac
dialog
--help
或者
Xdialog
--help
dialog --yesno "text string" <height> <width>
你输入dialog 或 Xdialog 后, 必须给定对话框的名字和你想设置的一引起特殊参数.#!/bin/sh这个脚本是如何工作的:
#
# pppdialout
#
#DIALOG=Xdialog
DIALOG=dialog
#
# 你的默认ISP的名字:
defaultisp=maxnet
#
error()
{
echo "$1"
exit 2
}
help()
{
cat <<HELP
pppdialout -- select an ISP and dial out.
All available ISPs must have a config file in /etc/ppp/peers
pppdialout executes the ppp-on/ppp-off scripts as described
in http://linuxfocus.org/English/March2001/article192.shtml
pppdialout, copyright gpl, http://linuxfocus.org/English/November2002
HELP
exit 0
}
# 分析命令行参数:
while [ -n "$1" ]; do
case $1 in
-h) help;shift 1;; # function help is called
--) shift;break;; # end of options
-*) echo "error: no such option $1. -h for help";exit 1;;
*) break;;
esac
done
tempfile=/tmp/pppdialout.$$
trap "rm -f $tempfile" 1 2 5 15
# 检查是否已经连接internet
if /sbin/ifconfig | grep '^ppp' > /dev/null; then
# 我们已经在线
$DIALOG --title "go offline" --yesno "Click YES to \
terminate the ppp connection" 0 0
rval="$?"
clear
if [ "$rval" = "0" ]; then
echo "running /etc/ppp/scripts/ppp-off ..."
/etc/ppp/scripts/ppp-off
fi
else
# 没发现internet连接, 进行连接
# 从 /etc/ppp/peers 取得可用的ISP列表
for f in `ls /etc/ppp/peers`; do
if [ -f "/etc/ppp/peers/$f" ]; then
isplist="$isplist $f =="
fi
done
[ -z "$isplist" ]&&error "No isp def found in /etc/ppp/peers"
#
$DIALOG --default-item "$defaultisp" --title "pppdialout" \
--menu "Please select one of\
the following ISPs for dialout" 0 0 0 $isplist 2> $tempfile
rval="$?" # return status, isp name will be in $tempfile
clear
if [ "$rval" = "0" ]; then
isp=`cat $tempfile`
echo "running /etc/ppp/scripts/ppp-on $isp..."
/etc/ppp/scripts/ppp-on "$isp"
else
echo "Cancel..."
fi
rm -f $tempfile
fi
# pppdialout 结束
dialog --menu "text" <height> <width> <menu height> <tag1> <description> ...
<height>, <width> 和<menu height> 被设置为0(自动调整,请看上面),然后是程序预定的语法格式的字符串(<tag1> <description>). 我们没有什么描述,就用了一些无意义的东西(==). 变量ipslist中的数据看起来像这样:isp1 == isp2 == isp3 ==
mktgz yourpackage .
这个程序会显示当前目录(".")下的所有文件, 然后你可以选择哪些文件需要加入到yourpackage.tar.gz 包中. 你可以在这里下载这个程序(mktgz.txt). 我们不算一句一句的解释这个脚本,因为你已经能够读懂这个脚本了.
|
主页由LinuxFocus编辑组维护
© Katja and Guido Socher, FDL LinuxFocus.org 点击这里向LinuxFocus报告错误或提出意见 |
翻译信息:
|
2003-04-06, generated by lfparser version 2.25