Linux Shell Scripting Tutorial (LSST) v1.05r3
Prev
Chapter 4: Advanced Shell Scripting Commands
Next

Input Box (inputbox) using dialog utility

$ cat > dia4
dialog --title "Inputbox - To take input from you" --backtitle "Linux Shell\
Script Tutorial" --inputbox "Enter your name please" 8 60 2>/tmp/input.$$

sel=$?

na=`cat /tmp/input.$$`
case $sel in
  0) echo "Hello $na" ;;
  1) echo "Cancel is Press" ;;
  255) echo "[ESCAPE] key pressed" ;;
esac

rm -f /tmp/input.$$

Run it as follows:
$ chmod +x dia4
$ ./dia4

Input Box (inputbox) using dialog utility

Inputbox is used to take input from user, In this example we are taking Name of user as input. But where we are going to store inputted name, the answer is to redirect inputted name to file via statement 2>/tmp/input.$$ at the end of dialog command, which means send screen output to file called /tmp/input.$$, letter we can retrieve this inputted name and store to variable as follows
na=`cat /tmp/input.$$`.
For input box's exit status refer the following table:

Exit Status for Input boxMeaning
0
Command is successful
1
Cancel button is pressed by user
255
Escape key is pressed by user

Prev
Home
Next
Confirmation Box (yesno box) using dialog utility
Up
User Interface using dialog Utility - Putting it all together