TryGOLD- Free

Mix It Up
Linux Magazine|#293/April 2025: Trojan Horse
Solve Bash blind spots by embedding other scripting languages into your Bash scripts to get the features you need. Pete shows you solutions for floating-point math, charting, GUIs, and hardware integration.
- By Pete Metcalfe
Mix It Up

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.

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.

MORE STORIES FROM LINUX MAGAZINEView all
MADDOG'S DOGHOUSE
Linux Magazine

MADDOG'S DOGHOUSE

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

time-read
3 mins  |
#293/April 2025: Trojan Horse
Cash as Cash Can
Linux Magazine

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.

time-read
9 mins  |
#293/April 2025: Trojan Horse
Innovator
Linux Magazine

Innovator

Re-inventing the Ubuntu experience

time-read
4 mins  |
#293/April 2025: Trojan Horse
Play video games natively on Linux Gaming Your Way
Linux Magazine

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.

time-read
9 mins  |
#293/April 2025: Trojan Horse
Installing mods on Steam Deck Steam Gems
Linux Magazine

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.

time-read
10+ mins  |
#293/April 2025: Trojan Horse
Zack's Kernel News
Linux Magazine

Zack's Kernel News

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

time-read
9 mins  |
#293/April 2025: Trojan Horse
System Monitoring
Linux Magazine

System Monitoring

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

time-read
4 mins  |
#293/April 2025: Trojan Horse
Exploring the Unbound DNS resolver Unbound
Linux Magazine

Exploring the Unbound DNS resolver Unbound

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

time-read
8 mins  |
#293/April 2025: Trojan Horse
MakerSpace
Linux Magazine

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.

time-read
6 mins  |
#293/April 2025: Trojan Horse

We use cookies to provide and improve our services. By using our site, you consent to cookies. Learn more