
While Bash has a huge variety of command-line tools that you can integrate into your code, sometimes you can still get stuck. Bash is extremely powerful, but, like all programming languages, it has its weakness. Some typical areas that can be challenging when using Bash include:
Floating-point math
Charting
Graphical user interfaces (GUIS)
Hardware integration
Command-line utilities can help address many of these topics, such as bc for floating-point math or Zenity [1] for user dialogs. While these tools are extremely useful, they may not give you the functionality or customization that you need. A common approach to solving this issue is to write standalone programs in another language, like Python, and then have your Bash script call that program.
You can also solve Bash limitations by embedding code from another scripting language (e.g., Lua, NodeJS, PHP, Python, or Tcl/Tk) within your Bash script. This method offers the advantage of keeping all the code in one script. In this article, I'll look at solving the issues of floating-point math, charting, GUIs, and hardware integration by embedding other scripting languages into Bash.
How to Embed Other Languages
There are several techniques for embedding other programming languages in Bash. For very small code bits, a string of text can be piped to the other scripting language’s interpreter as follows:
Here, a string of commands are piped to Python. A semicolon is used to separate each command. To return the result to Bash, a Python print statement is used.
Some languages, such as Julia and Python, have command-line options to pass in a string of commands (see Listing 1). Commandline options offer the slight advantage of not using a pipe or an echo statement.
This story is from the {{IssueName}} edition of {{MagazineName}}.
Start your 7-day Magzter GOLD free trial to access thousands of curated premium stories, and 9,000+ magazines and newspapers.
Already a subscriber ? Sign In
This story is from the {{IssueName}} edition of {{MagazineName}}.
Start your 7-day Magzter GOLD free trial to access thousands of curated premium stories, and 9,000+ magazines and newspapers.
Already a subscriber? Sign In

MADDOG'S DOGHOUSE
Planning and community effort can help welcome Linux beginners online without precluding more advanced discussions.

Cash as Cash Can
Mike Schilli uses the YNAB tool to keep an eye on his finances. Until recently, YNAB didn't have a terminal Ul programmed in Go, but Mike delivers it here.

Innovator
Re-inventing the Ubuntu experience

Play video games natively on Linux Gaming Your Way
Bazzite, an immutable Linux distro adapted for gaming, lets you play your favorite video games on your PC, handheld, or home theater PC.

Installing mods on Steam Deck Steam Gems
The Steam Deck gaming console offers a galaxy of creative modifications for the games you love to play.

Zack's Kernel News
Chronicler Zack Brown reports on the latest news, views, dilemmas, and developments within the Linux kernel community.

System Monitoring
Mission Center, a graphical system monitor, groups all important system statuses in a compact, intuitive interface.

Exploring the Unbound DNS resolver Unbound
The Unbound DNS resolver offers comprehensive security and many other useful features.

MakerSpace
If you need to store long-term historical data, you can cobble together some Arduino modules, sensors, and displays and get them all to talk to an SQL server.