shell的圖形化實現簡單示例(r3筆記第70天)
阿新 • • 發佈:2022-05-04
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
dialog --title Testing --msgbox 'This is a new test by Jianrong' 10 20
--yesno元件 dialog --title "Please answer" --yesno "Do you want to have this testing " 10 20
--inputbox元件 dialog --inputbox "Enter your name" 10 20 Jianrong
--fselect元件 dialog --title "select a file " --fselect $HOME 10 20
更多的細節還有待學習提高。