by Katja and Guido Socher <katja(at)linuxfocusorg, %20guido(at)linuxfocus.org>
About the authors:
Katja ��LinuxFocus�ĵ¹��༭. ��ϲ��Tux, ��Ӱ, ��Ӱ�ʹ���. ������������ҳ.
Guido ��һ������linux������. ��ϲ��Linux��Ϊ�����ɳ�ʵ�Ϳ��ŵ��������Ƶ�. ���������dz�֮Ϊ"����Դ����"��ԭ��.
������������ҳ:linuxfocus.org/~guido.
Ŀ¼:
|
(X)dialog: Talking shells
ժҪ:
Xdialog��dialog��������ʹ����shell�ű��߱�ͼ���û�����(GUI)�Ĺ���.
����Ҫ�߱�һЩshell����֪ʶ���ܿ�����ƪ����. �����Կ����ǵ�Shell
Programming��ƪ������ѧһЩshell���̵Ļ���֪ʶ.
����
��ʹû��ͼ���û�����, UNIX shell��������һ���dz���Ч�Ĺ�������.
��ijЩԭ��ʹ����һ��ͼ�εĶԻ�����ʹ�û����ø���ֱ��. ����һ�������İ�װ�Ի���. ���д�����ѡ������ѡ����װ������,������ѡ��Ŀ��Ŀ¼....
ʹ�� (X)dialog...
ʹ��dialog��Xdialog������Ҫдһ���̶̵�shell�ű��Ϳ���ʵ��һ��ͼ�εĻ�Ӧ�ó���. Dialog��һ����ȫ�������ն˵ij���,
Xdialog����һ��X11����.
������һ������:
����������(�� ����/ճ��)������Щ���䵽һ��shell������(xterm,konsole,...):
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����Xdialog (�������Ľű����ڶ��е� X ȥ��), ���Ϳ��Կ���һ��������xterm���Ļ���curses�ij���,������һ�������Ĵ�����(��ͼ).
��ijЩ������, ���������з�ʽ���ʺ�һ������Ҫ��һ���ն˴������еĽű�. �����������������ڶ�̨������ֱ��·�ɵ�������.
����������dialog����˳�����ж�Xdialog������.
������Щdialog/Xdialog������Ư���������ô�, ������˵���˱�дһ��ͼ�λ��ĶԻ���������. ����������Ȥ�ĶԻ���,
����������,�˵�,�ļ�������,������,�ı�����,��Ϣ��,������,.....��������������:
dialog
--help
����
Xdialog
--help
���õ�һ�����õĶԻ����б�. Xdialog ӵ�еĶԻ�������Ҫ��dialog��.
�����������
��Щ�Ի�����ͨ��������������������.
dialog --yesno "text string" <height>
<width>
������dialog �� Xdialog ��, ���������Ի��������ֺ��������õ�һ������������.
"yesno"�Ի�����3������. <height>��<width>��������Ϊ0,
�Ի����������ı��ij����Զ��������Ⱥ߶�. �������ѶԻ�������״̬���ظ��ű���������"$?"������.
�������и�����ֵ��Ҫ����,�类ѡ��������, ������ֵ�ᱻ���ص���������(standard error).
������ͨ��ֻ�DZ���ӡ����Ļ��,��������"2>"�������ض���.
һ���dz�����Ч�Ľ����취.
�����ij���
����,����������һ��ʵ�õij���,Xdialog/dialog���ȴ�ͳ��shell�ű������ṩ�����ı���:
һ���ÿ���ѡ����ͬ��ISP(Internet Service Providers)���ҽ������ӵIJ˵�. �����ű���Ҫ2001��5�µ����� Using
different ISPs for your Internet access ���ṩ��ppp-on/ppp-off�ű�.
���������ű����� pppdialout,
�����������Ƿ�������ʾ����ͬ�IJ˵�.
#!/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 ����
�����ű������ι�����:
��ʼ,���Ƕ�����һЩ����:error��help, ��һ�����Ǽ��������в���,Ȼ��������һ����ʱ�ļ�(/tmp/pppdialout.$$).
$$�ǵ�ǰ���е�����,����ÿһ���������ж��Ƕ�����. �ݾ������ڳ�����ǿ���ж�(���û�����Ctrl+C)��ִ�в���ɾ�����Ƕ�������ʱ�ļ�.
Ȼ���Ҽ��������Ƿ��Ѿ�����(����:/sbin/ifconfig | grep '^ppp'). ���������Ѿ�����������һ���Ի���,
����������������������, ѯ���û��Ƿ�Ҫ������. �������Dz����߾ʹ���һ���˵��Ի���. ���Ǵ� /etc/ppp/peers (ls
/etc/ppp/peers)��ȡ�����п��õ�ISPs. �˵��Ի��������:
dialog --menu "text" <height> <width>
<menu height> <tag1> <description> ...
<height>, <width> ��<menu height>
������Ϊ0(�Զ�����,�뿴����),Ȼ���dz���Ԥ�������ʽ���ַ���(<tag1> <description>).
����û��ʲô����,������һЩ�������Ķ���(==). ����ipslist�е����ݿ�����������:
isp1 == isp2 == isp3 ==
�û���ѡ�������ᱻ��ӡ��������. ����"2> $tmpfile" ����һ����д�����ǵ���ʱ�ļ�(tmpfile)��.
�����˵��Ի�����cancel��ѡ, �������DZ������� $? (�˳�״̬) ��ȷ����һ����������.
����, �����Ѿ��㹻. ����������������:
... Xdialog������Ư����GTKͼ�ν���:
![[pppdialout with xdialog]](../../common/images/article267/xdialog_1.gif)
![[pppdialout with xdialog]](../../common/images/article267/xdialog_2.gif)
... �ն������� curses
�� dialog :
![[pppdialout with dialog]](../../common/images/article267/dialog_1.gif)
![[pppdialout with dialog]](../../common/images/article267/dialog_2.gif)
�����ij���More applications
���ǻ�����һ������Ҫ����. ����һ������mktgz��ʹ��Xdialog��checklist�Ի����ij���.
����ƽ���ն˵�dialogû��checklist�Ի���,������ֻ��ʹ��Xdialog��. �������� mktgz������ tar.gz ��ѹ����.
�÷�:
mktgz yourpackage .
������������ʾ��ǰĿ¼(".")�µ������ļ�, Ȼ��������ѡ����Щ�ļ���Ҫ���뵽yourpackage.tar.gz ����.
������������������������(mktgz.txt).
���Dz���һ��һ���Ľ��������ű�,��Ϊ���Ѿ��ܹ����������ű���.
Xdialog �� dialog �Դ���һЩ������һ����"samples"��Ŀ¼��(Redhat 7.3 ����
/usr/share/doc/Xdialog-2.0.5/samples��). ��ע����Щ�ű�������������ʾ, ���ǻ�����ȥ��һЩ����.
�ܽ�
Xdialog �� dialog �ṩ�˴����ĶԻ�������. ������Щ���͵ĶԻ����ʺ��������͵Ľű�. shell
��������һ��"ǿ��"�Ļ���. ��tab�����Զ���ȫĿ¼����ͼ���û������е�������Ҫ���ܶ�. �ر��ǹܵ���������������һ��ǿ���Ĺ���. ��������:
grep -i "somestring" file.txt | sort | uniq | wc -l
(UNIX��shellsҪ��ͬ��������û����ô����: ����file.txt������"somestring"�ִ����е���Ŀ)
���������ֹܵ��ṹ����Ϊ��Щ����ȫ�������в���������. ���仰˵: ���Dz���ͣ�������û��������μ�������.
��Ȼ�ڳ�����ͼ�ζԻ����dz�����, Xdialog �� dialog �dz�����ʹ��,
���ؾ�û��������ͼ�λ�����ǿ��. �����һ��ASCII shell�ű���ȫͼ�λ�����������ȱ��.
���������� Xdialog �� dialog?
���ȿ����ҵĵط�������linux���а�������. Ҳ���Ѿ���װ�������ļ�������(��ѯ���ļ�����: �� rpm -qil Xdialog,
dpkg -L Xdialog). Xdialog����ҳ��:
http://www.chez.com/godefroy/
dialog����ҳ��:
http://hightek.org/dialog/
��Ҳ������������ dialog/Xdialog.
�����
����ƪ���·�������
ÿƪ���¶��и��Եķ���ҳ�档������ҳ����������ύ���ۣ�Ҳ���Բ鿴�������ߵ����ۣ�
2003-04-06, generated by lfparser version 2.25