Tuesday, 6 August 2019

How to Add a GUI to Linux Shell Scripts

A zenity information window launched from a Ubuntu terminal.

You can use GUI windows, sliders, radio buttons, progress bars, and more in your Bash scripts. Learn how to use the zenity toolkit and give your Bash scripts a facelift. We’ll show you how.

Bash scripting is a powerful programming language and, because it’s built into the Bash shell, it’s readily available to everyone. It’s an easy language to start programming in. Because it’s interpreted, you don’t need to compile your scripts. As soon as you’ve edited the script file and made it executable, you can run it. This makes the coding, running, and debugging cycle quite efficient.

There are two main complaints people have with Bash scripts, and the first is speed. Because the Bash shell interprets the commands in the script, they don’t execute as quickly as compiled code. However, this is like complaining that a tractor isn’t as fast as a car; they’re meant for different things.

There are two kinds of speed, though. You can often knock together a quick script and use it to perform a task much more quickly than developing a solution in a compiled language, such as C.

The second complaint people have with Bash scripts is the user interface—it’s a terminal window. Of course, sometimes the interface doesn’t matter. If the only person who’ll ever use the script is its author, the interface probably isn’t that important. Nor does it matter for scripts that perform background and batch type processing. Typically, such scripts don’t need much (if any) user interaction.

There are occasions when you do need something a little more intuitive and modern than the terminal window. Most people are familiar with a graphical user interface (GUI). To give people an experience that’s as frictionless as possible, you have to create and use GUI elements from your scripts.

The zenity Application

zenity allows you to incorporate a wide range of graphical interface elements in your Bash scripts. It’s a powerful toolkit that gives your scripts a modern feel and a contemporary, familiar appearance.

zenity is preinstalled on Ubuntu, Fedora and Manjaro distributions. It’s part of GNOME. If you use KDE, you might want to check out  kdialog  instead, although zenity does run on any desktop environment.

Read the remaining 137 paragraphs



from How-To Geek https://ift.tt/2Yt2hL5

No comments:

Post a Comment