Bash: Guides and Practical Know-how | Page 9 | mironsoft Blog
Bash
-
Aug 12, 2025
A Bash script running as a daemon or long-lived process must handle SIGINT, SIGTERM and SIGHUP without leaving behind orphaned lock files or half-written output. A single trap call can register the same handler for several signals, but telling the signals apart inside the handler and avoiding double runs when combined with an EXIT trap takes a few extra tricks.
-
Aug 7, 2025
A --help text disappears the moment the terminal closes, while a man page stays behind as a searchable document in the system, reachable through man at any time. With pandoc converting a Markdown document, or help2man building directly from the --help output, that gap closes for a homegrown Bash script without any manual troff work.
-
Aug 4, 2025
A good Magento workflow depends heavily on using the right commands. In a Mark Shust setup, the wrappers in the `bin/` directory are the clean way to handle Magento, Composer, logs, debugging, the database and code quality.
-
Jul 31, 2025
The operator [[ $string =~ regex ]] evaluates regular expressions directly in Bash and, on a match, fills the BASH_REMATCH array with the full match and every capture group. Anyone who knows this mechanism can parse log lines, version numbers, or configuration values without starting a single external process, but also needs to keep the limits of the POSIX ERE dialect versus grep, sed, and PCRE in mind.
-
Jul 31, 2025
The first line of a Bash script decides which interpreter runs it, and that single line is one of the most common reasons a script fails to start on someone else's machine. The difference between #!/usr/bin/env bash and #!/bin/bash looks trivial but has concrete consequences on macOS, on Nix systems, and in containers with an unusual Bash install path.
-
Jul 30, 2025
Anyone who waits for a nightly cron job to tally up the error count loses valuable reaction time. Streaming logs in real time with tail -f, inotifywait, and while read turns passive log files into active monitoring sources, with instant alerting, safe aggregation, and traceable pipelines built directly in Bash.
-
Jul 30, 2025
Anyone restarting an external command thousands of times inside a loop is wasting runtime on repeated process startup. A coprocess keeps exactly one such command alive permanently in the background and lets the shell talk to it in both directions over two file descriptors, instead of spawning a new child process for every single request.
-
Jul 29, 2025
Most shell developers know | grep and 2>&1, but few truly understand the complete file descriptor model that sits underneath. Once you understand it, you write I/O redirections without mistakes, use exec for persistent redirection, and combine tee, here-docs and here-strings elegantly for complex data flows.
-
Jul 29, 2025
trap ERR and trap EXIT sound like two flavors of the same mechanism, but they behave completely differently. EXIT fires guaranteed, ERR shares the exact same blind spots as set -e. Combining both makes clear when custom stack traces built with BASH_LINENO become necessary, and how to log failures reliably instead of letting them slip by silently.
-
Jul 27, 2025
A cron job that runs longer than its scheduled interval quietly starts a second time, even though the first run has not finished yet. Two parallel database exports, two simultaneous backup processes, or two import scripts blocking each other are the result, often without an immediately visible error message. This article shows how flock reliably prevents overlapping cron jobs, both directly in crontab and inside scripts, and where the limits of simpler locking approaches lie.