Author: The Aha Unix Team

Backslash Continuation In Bash: Controlling With The -R Flag

Controlling Backslash Continuation in Bash Scripts The backslash character in Bash scripts allows wrapping long commands over multiple lines for improved readability. This technique is known as backslash continuation. Using backslash continuation structures lengthy pipelines, nested commands, and other complex logic without loss of functionality. However, unintended consequences can occur when using backslash continuation, such…

Eliminating Leading And Trailing Whitespace With Ifs In Bash Scripts

The Problem: Extra Whitespace Causing Issues in Scripts Whitespace characters like spaces, tabs, and newlines are ubiquitous in text data. Often, these characters inadvertently get introduced at the beginning or end of strings read into Bash scripts. This can cause problems when processing or passing around such values in scripts. For example, a script may…

Performance Benchmark – [ Vs [[ In Bash Conditionals

Comparing Performance of [ vs [[ in Bash Bash provides two ways of executing conditional expressions – the traditional [ command, and an improved [[ keyword added in Bash version 2.0. Understanding the differences between these can help explain the performance benchmarks outlined later in this article. [ is the original conditional expression evaluation utility…

Arithmetic Expressions In Bash – Using (( And $(( For Math

Performing Math in Bash Shell Scripts Bash provides built-in support for integer arithmetic operations through two main constructs – double parentheses (( )) and dollar-double parentheses $(( )) expressions. Both allow performing common math calculations directly inside Bash scripts and at the command line interface. Arithmetic expressions enable substitution of numeric variables and calculations into…

When To Use ( Vs [[ Vs [ – A Guide To Bash’S Conditional Syntax Forms

Deciding Between Test, Double Bracket, and Single Bracket Conditionals Explaining the key differences between (, [[, and [ Bash provides three primary methods for evaluating conditional expressions: test (()), double bracket [[]], and single bracket []. Understanding when to use each syntax form is key to writing efficient and robust Bash scripts. The test command…

Daemonizing Processes The Right Way With Daemonize

What is a Daemon Process and Why Daemonize A daemon process refers to a computer program that runs as a background process, rather than being under the direct control of an interactive user. Daemon processes typically start at system boot and operate independently in the background, handling tasks like logging, network connectivity, cron jobs, and…

Running Processes In The Background: Best Practices And Pitfalls

Launching Background Processes A background process runs without blocking the shell, allowing the user to continue typing commands at the prompt while the process executes. The shell does not wait for background processes to finish before prompting for further input. Contrast this with foreground processes, which fully occupy the shell terminal – no new commands…

Preventing Processes From Being Killed: An Overview Of Nohup And Disown

The Problem: Processes Getting Killed on Logout When a user logs out of a Linux/UNIX system, the shell and associated processes are disrupted. Any foreground processes the user started are sent the HUP (hangup) signal by the shell. This signal causes processes to terminate by default. Background processes not disowned also receive HUP and may…

When To Use Nohup Vs Disown For Long-Running Processes

The Core Difference Between nohup and disown The Linux utilities nohup and disown both allow processes to continue running in the background after a user logs out or closes their terminal. However, nohup and disown achieve process persistence through different mechanisms: nohup configures a process to ignore SIGHUP signals, which are sent to processes when…

Demystifying Background Processes: Nohup, Disown And & Explained

Keeping Processes Running After Terminal Closure When a shell session is closed or a terminal window is exited, any processes started in that session are also terminated by default. However, often we want processes to continue running in the background even after closing the terminal. There are several methods in Linux to achieve this: nohup…