Recently, i have a new task which is adding a user account on a Linux box with UI login shell. My project leader suggests a few tools for me to study and finally i pick the the one called pdmenu.
pdmenu is based on dialog command in Linux. So before talking about pdmenu, i would like to show you how to use dialog.
you can install dialog to create simple message box in command console. For Ubuntu user, just apt-get dialog.
1. Create a Hello World message box
dialog --title "Hello" --msgbox 'Hello world!' 6 20
- title – Title of the message box
- msgbox – The text in the message box
- 6 20 – The size of the message box
2. Create a Yes/No message box
dialog --title "Message" --yesno "Are you OK?" 6 25
The box return 0 if yes is chosen and 1 if no.
3. Create a simple menu
dialog --menu "Menu" 10 30 3 1 red 2 green 3 blue 2>temp
Similar to yes/no box, it return 0 if OK and 1 if Cancel. And the selection (1, 2, 3) will be printed in stdout which is direct to a file named as “temp”.
4. Example
The following is a shell script example which help u to list file in /home, /root or /tmp directory.
#!/bin/sh dialog --menu "List file of a directory" 10 30 3 1 /home 2 /root 3 /tmp 2>temp # OK is pressed if [ "$?" = "0" ] then _return=$(cat temp) # /home is selected if [ "$_return" = "1" ] then dialog --title "List file of directory /home" --msgbox "$(ls /home -l)" 100 100 fi # /root is selected if [ "$_return" = "2" ] then dialog --title "List file of directory /root" --msgbox "$(ls /root -l)" 100 100 fi # /tmp is selected if [ "$_return" = "3" ] then dialog --title "List file of directory /tmp" --msgbox "$(ls /tmp -l)" 100 100 fi # Cancel is pressed else echo "Cancel is pressed" fi # remove the temp file rm -f temp
There are other examples which can be found at Dialog: An Introductory Tutorial
Done and I will talk about pdmenu later =).
Nice one , But i was searching the implementation using API’s or system calls in Linux 🙂
LikeLike
Thanks. i have no idea how to implement this with lower level linux call. I think that maybe interesting so let me know if you have any findings.
by the way, i got another post about creating menu using pdmenu. See if you are interested. but the pdmenu is built on top of dialog which is not what you want. =P
pdmenu – Create a Simple Menu for Inexperienced Linux Users
LikeLiked by 1 person
Hi there , i have a dunnos
Well its need it
Read Values from ???
Okey i just trying to understand
well i wanna make a Dialog GUI Selector , and when i choise some option , this in the process show a gauge / progress bar .
I put here the script i try to do ->
LikeLike
The dialog box will have 2 buttons. If the user select OK, 0 is returned.
LikeLike