shell的图形化实现简单示例

shell脚本一直以来就给人呆板枯燥的感觉。如果来点图形的感觉可能大家对shell的感觉就会多加分。其实在linux中已经有人做了不少的工作,目前使用比较多的是dialog,还有很多衍生的版本,比如kdialog,gdialog,zenity等等。都在图形接口上有自己的界面风格和特点。
安装dialog,一般Linux中都会默认安装这个包,如果没有可以使用yum install来做。

[root@rac1 ~]# yum install dialog
Loaded plugins: fastestmirror
Determining fastest mirrors
addons                                                                                                                                           | 1.9 kB     00:00    
base                                                                                                                                             | 1.1 kB     00:00    
base/primary                                                                                                                                     | 1.3 MB     00:01    
base                                                                                                                                                          3667/3667
extras                                                                                                                                           | 2.1 kB     00:00    
extras/primary_db                                                                                                                                | 173 kB     00:00    
update                                                                                                                                           | 1.9 kB     00:00    
update/primary_db                                                                                                                                | 139 kB     00:00    
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package dialog.x86_64 0:1.0.20051107-1.2.2 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================================================================
 Package                              Arch                                 Version                                             Repository                          Size
========================================================================================================================================================================
Installing:
 dialog                               x86_64                               1.0.20051107-1.2.2                                  base                               165 k

Transaction Summary
========================================================================================================================================================================
Install       1 Package(s)

Total download size: 165 k
Installed size: 393 k
Is this ok [y/N]: y
Downloading Packages:
dialog-1.0.20051107-1.2.2.x86_64.rpm                                                                                                             | 165 kB     00:00    
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
** Found 5 pre-existing rpmdb problem(s), 'yum check' output follows:
PackageKit-0.5.8-13.el6.x86_64 has missing requires of PackageKit-yum = ('0', '0.5.8', '13.el6')
PackageKit-0.5.8-13.el6.x86_64 has missing requires of PackageKit-yum-plugin = ('0', '0.5.8', '13.el6')
abrt-addon-ccpp-1.1.13-4.el6.x86_64 has missing requires of yum-utils
perl-DBD-Pg-2.15.1-3.el6.x86_64 has missing requires of libpq.so.5()(64bit)
rhn-check-1.0.0-38.el6.noarch has missing requires of yum-rhn-plugin >= ('0', '0.5.3', '30')
  Installing : dialog-1.0.20051107-1.2.2.x86_64                                                                                                                     1/1
  Verifying  : dialog-1.0.20051107-1.2.2.x86_64                                                                                                                     1/1

Installed:
  dialog.x86_64 0:1.0.20051107-1.2.2                                                                                                                                   

Complete!

安装完成后,我们来看看效果。dialog提供的选项功能还是很丰富的,自己也学习了个皮毛,简单show一下。
  -->msgbox组件
  dialog --msgbox 'this is test' 50 50
shell的图形化实现简单示例_第1张图片
  dialog --title Testing --msgbox 'This is a new test by Jianrong' 10 20
shell的图形化实现简单示例_第2张图片
 --yesno组件
  dialog --title "Please answer" --yesno "Do you want to have this testing " 10 20
shell的图形化实现简单示例_第3张图片
 --inputbox 组件
  dialog --inputbox "Enter your name" 10 20  Jianrong
shell的图形化实现简单示例_第4张图片
  --fselect组件
  dialog --title "select a file " --fselect $HOME 10 20
shell的图形化实现简单示例_第5张图片

更多的细节还有待学习提高。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/23718752/viewspace-1352091/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/23718752/viewspace-1352091/

你可能感兴趣的:(shell的图形化实现简单示例)