Versuchen GOLD - Frei

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:

imageHere, 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.

Linux Magazine

Diese Geschichte stammt aus der #293/April 2025: Trojan Horse-Ausgabe von Linux Magazine.

Abonnieren Sie Magzter GOLD, um auf Tausende kuratierter Premium-Geschichten und über 9.000 Zeitschriften und Zeitungen zuzugreifen.

Sie sind bereits Abonnent?

WEITERE GESCHICHTEN VON Linux Magazine

Linux Magazine

A couch-gaming OS based on Big Picture streaming Game Master

Play Steam, GoG, and Epic games with one steamy and epic OS.

time to read

8 mins

#297/August 2025: Cleaning Up

Linux Magazine

Shopping Frenzy

To gain insight into his Amazon orders, Mike Schilli writes a Go program that runs statistics and displays the results graphically.

time to read

10 mins

#297/August 2025: Cleaning Up

Linux Magazine

Zack's Kernel News

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

time to read

10 mins

#297/August 2025: Cleaning Up

Linux Magazine

FOSSPicks

Sparkling gems and new releases from the world of Free and Open Source Software

time to read

14 mins

#297/August 2025: Cleaning Up

Linux Magazine

Create interactive fiction with Inform Storyteller

Inform is your guide to the strange worlds of interactive fiction and text-driven games.

time to read

12 mins

#297/August 2025: Cleaning Up

Linux Magazine

MakerSpace Send Raspberry Pi and Arduino notification messages to your desktop You've Been Notified

If you use sensors with a Raspberry Pi or Arduino in your home network, you may want to get desktop notifications on your Linux PC whenever some interesting event is detected. You can send messages via SSH or through simple TCP connections and display them with notify-send.

time to read

4 mins

#297/August 2025: Cleaning Up

Linux Magazine

Linux Magazine

Tuning tools for AMD graphics chips Clockwork

CoreCtrl and RadeonTop monitor the utilization and clock frequency of AMD chips with the potential for boosting performance.

time to read

5 mins

#297/August 2025: Cleaning Up

Linux Magazine

Linux Magazine

Window of Opportunity

Add graphics that automatically update. We show you how to build an analog clock widget with the Cairo and GTK libraries.

time to read

11 mins

#297/August 2025: Cleaning Up

Linux Magazine

Linux Magazine

MADDOG'S DOGHOUSE

The prohibitive expense of early proprietary supercomputers is just part of why Linux has taken (and kept) the lead in this area.

time to read

3 mins

#297/August 2025: Cleaning Up

Linux Magazine

Linux Magazine

Notification Nirvana

If you host a lot of services on your home server, it helps to have them send you timely notifications. With ntfy, you can send push notifications to your phone or desktop. By Koen Vervioesem

time to read

9 mins

#297/August 2025: Cleaning Up