In this first article, I introduce you to a tool called Whiptail. This is a program that allows you to build simple GUI applications for shell/bash scripts.
You can read more about the build GUI application for bash scripts with Zenity.
How to install Whiptail?
Table of Contents
Installing whiptail on Linux is quite simple.
For Ubuntu operating system and Ubuntu base, you use the following command.
sudo apt-get install whiptail -y
For CentOS and base CentOS operating systems, use the following command.
sudo yum install newt -y
After the installation is complete, you can check the current version of the installed program.
daniel@daniel-laptop:~/Desktop$ whiptail -v
whiptail (newt): 0.52.20
Build the first bash GUI application with Whiptail
Now, we will do a simple example with Whiptail. Copy the contents of the script below onto your computer and name the file, for example, whiptail.sh
.
#!/bin/bash
NAME=$(whiptail --inputbox "Type name of the blog:" 8 78 Name --title "DevOpsLite.com GUI" 3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus = 0 ]; then
echo "Type name Ok and entered" $NAME
echo "Welcome to $NAME" > name_test
whiptail --textbox name_test 12 80
else
echo "Type name Cancel."
fi
echo "(Exit status was $exitstatus)"
Next you use the command below to run the script.
bash whip.sh
And see what happens. An interface you’ve probably encountered somewhere, right?
There are a lot of setup programs that use the GUI to look like that.
Conclusion
At this point, you will not fully understand how to use whiptail but that’s okay, in the next articles, I will show you how to use it. Using Whiptail will help you be able to build your applications more user friendly. Not always just the command line.
(This is an article from my old blog that has been inactive for a long time, I don’t want to throw it away so I will keep it and hope it helps someone).