Other than just displaying messages, scripts also take input from user. Whiptail can be used to create a small GUI for the user to enter his or her input.
To create an input box we need to use the option –inputbox, the syntax being
By default whiptail passes the input entered to the standard error console, and in a usual shell we will be able see the entered text on the terminal after we exit from the whiptail window.
But if we want to use the entered input by storing it in some variable, we will have to go about a few manipulations as there is no direct way of doing it in whiptail.
The simple manipulation we will have to do is swap the standard error console and the standard output console which can be done by appending
to the command.
Thus we can write the whiptail command as
The varialbe val will get the value that is entered in the inputbox.
Here is an example script to see the use if inputbox
Give the script execute permission and run it to see the output