Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dialog from bash script

I want create a simple graphical (Qt, Gtk, ...) dialog, concretly a simple print dialog, as a "frontend" to lpr, in bash. What I want? How many pages per page, printing interval. It's (at least) two options.

What is the best util(s) to solve this problem?

like image 666
uzsolt Avatar asked Dec 02 '11 09:12

uzsolt


People also ask

What is dialog in bash?

The dialog command allows you to display a variety of questions or display messages using dialog boxes from a shell script. Use the dialog utility for creating TTY (terminal) dialog boxes.

What is $_ in bash?

$_ (dollar underscore) is another special bash parameter and used to reference the absolute file name of the shell or bash script which is being executed as specified in the argument list. This bash parameter is also used to hold the name of mail file while checking emails.

How do I open a dialog box in Linux?

By default you can open it with Alt - F2 or Alt - Space .

What is dialog in Linux?

Dialog is an application used in shell scripts which displays text user interface widgets. It uses the curses or ncurses library. The latter provides users with the ability to use a mouse, e.g., in an xterm. dialog. Dialog - editbox widget.


1 Answers

There is

  • dialog (ncurses based)
  • xdialog (X11 based)

Other implementations are reported to exist:

  • zenity (Gnome)
  • kdialog (Kde)

If you use gpm, you can even use the mouse in a console environment. It requires a tty, so it will work over ssh, screen, xterm etc. but not when piping/redirecting.

Both sport more or less the same interface so you can switch depending on whether an X display is available

Here is a dialog script that displays a simple YES/NO box:

#!/bin/bash
DIALOG=${DIALOG=dialog}

$DIALOG --title " My first dialog" --clear \
        --yesno "Hello , this is my first dialog program" 10 30

case $? in
  0)
    echo "Yes chosen.";;
  1)
    echo "No chosen.";;
  255)
    echo "ESC pressed.";;
esac

enter image description here

Replacing dialog by xdialog:

enter image description here

like image 51
sehe Avatar answered Sep 20 '22 07:09

sehe