开发者

Blue Input Screen (Shell Script)

In Ubuntu Server 10.04

Sometimes when i'm 开发者_运维问答installing some packages through apt-get, it prompts me with a blue dialog and asks for input/selection.. E.G: when installing mysql-server, it prompts me for a root password.. How can i accomplish this in my own shell script, so that same blue dialog will show up when i need to ask yes/no and password questions?


Use dialog. Read more about it here and here.


You're looking for dialog.


Try the ncurses library.

http://www.gnu.org/software/ncurses/

There are some examples of using ncurses stuff (including dialog, which is what's probably being used in your examples) from bash here:

http://subsignal.org/doc/AliensBashTutorial.html


In a fairly modern bash:

$ read -p 'Password? ' -s; echo "[$REPLY]"


You can use zenity or yad within your shell script. yad (Yet Another Dialog) has been a fork of zenity to remove obsoleted dependencies (libglade and gnome-canvas) at a time when zenity project was frozen. But now both projects continue to evolve (in different directions)...

You can still use ancestors: gdialog, cdialog, xdialog and dialog.

zenity can be used in Python (PyZenity), in Ruby (Zerenity, Zenity.rb) and in many shells: bash, tcsh, dash, zsh... and even in MS-Windows shell!

Zenity basic example:

#!/bin/sh
if zenity --question --text="Please press a button."
then
   zenity --info     --text="You pressed Yes\!"
else
   zenity --error    --text="You pressed No\!"
fi
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜