Bash Operators & Shell Tricks: Level Up Your Scripting

Learn about logical operators and shell expansions, in the second article in this multi-part series on programming with Bash. Author’s note: The articles in this series first appeared at Opensource.com. The original articles consisted of two series and the rest were published as stand-alone articles. These have all been merged into a single series with updates and modifications for that purpose.

Source: Bash Operators & Shell Tricks: Level Up Your Scripting – OpenSource.net

Here Today, Gone When You Exit: Proper Tempfiles in Shell Scripts

In the course of my career, I’ve periodically come across code like this in shell scripts:

TEMP_FILE=/tmp/tempfile

Or sometimes, slightly more elegantly:

TEMPFILE=/tmp/tempfile.$$

The problems with the first example are obvious, especially if it appears in many different scripts. The second is better. The “$$” means “my process ID”, who if whatever script had a process ID of 5309, the TEMPFILE variable would be set to /tmp/tempfile.5309. This makes collisions between scripts extremely unlikely, but is still suboptimal. What if there is a file called /tmp/tempfile.5309 and it’s owned by another user, or what if you don’t have permission to write to /tmp? It’d be better to find out immediately than many lines later when you try to write something. …

Source: Here Today, Gone When You Exit: Proper Tempfiles in Shell Scripts – LowEndBox

Boost Up Productivity in Bash – Tips and Tricks

When spending most of your day around bash shell, it is not uncommon to waste time typing the same commands over and over again. This is pretty close to the definition of insanity.

Luckily, bash gives us several ways to avoid repetition and increase productivity.

Today, we will explore the tools we can leverage to optimize what I love to call “shell time”.

Source: Boost Up Productivity in Bash – Tips and Tricks | Linux Journal

Use the Unofficial Bash Strict Mode (Unless You Looove Debugging)

I call this the unofficial bash strict mode. This causes bash to behave in a way that makes many classes of subtle bugs impossible. You’ll spend much less time debugging, and also avoid having unexpected complications in production.

Source: Use the Unofficial Bash Strict Mode (Unless You Looove Debugging) (aaron maxwell)