PowerScripting All articles
Tutorials & How-Tos

Seven Built-In Features Hiding in Your Terminal That Do the Heavy Lifting for You

PowerScripting
Seven Built-In Features Hiding in Your Terminal That Do the Heavy Lifting for You

The most powerful tools in a developer's toolkit are frequently the ones already installed. No plugins, no dependencies, no npm install at 11 p.m. waiting on a registry. Just features sitting in your shell, waiting for someone to read the manual. Here are seven worth knowing.

1. Bash trap: Cleanup That Actually Runs

trap 'rm -rf "$TMPDIR"; echo "Cleaned up"' EXIT

Register cleanup logic against the EXIT signal and it fires whether your script finishes, fails, or gets killed. This saved a week during a migration where leftover temp files were corrupting subsequent runs — one line, problem gone.

2. Process Substitution: Compare Without Temp Files

diff <(sort prod.conf) <(sort staging.conf)

<(command) feeds a command's output into another command as if it were a file. Diffing two remote configs, two directory listings, two API responses — no intermediate files to clean up.

3. set -euo pipefail: Fail Fast, Fail Loudly

#!/usr/bin/env bash
set -euo pipefail

Unset variables become errors, failed commands stop the script, and pipeline failures propagate. It turns silent partial failures into immediate, debuggable exits. Every serious Bash script should start this way.

4. PowerShell Calculated Properties

Get-Process |
  Select-Object Name, @{Name='MemoryMB'; Expression={[math]::Round($_.WorkingSet64/1MB,1)}}

Transform data inline instead of writing a post-processing loop. Reports, CSV exports, and dashboards get dramatically shorter.

5. jq-Style Pipelining in PowerShell (It's Native)

(Invoke-RestMethod https://api.github.com/repos/[powershell](https://en.wikipedia.org/wiki/PowerShell)/powershell).stargazers_count

Invoke-RestMethod deserializes JSON into real objects — no parsing library, no string wrangling. Dot into the response directly. Once you internalize this, shell-based API scripting stops feeling like a workaround.

6. Bash Brace Expansion for Bulk Operations

cp app.conf{,.bak}
mkdir -p src/{core,api,tests,docs}

The first line is the everyday gem: an instant backup copy. The second builds four directories in one shot.

7. readonly and local: Variables That Respect Scope

process_file() {
  local input="$1"
  readonly MAX_RETRIES=3
}

Constants that cannot be clobbered and locals that cannot leak. Half of all shell script bugs are variable collisions; these two keywords eliminate most of them at the source.

The Common Thread

None of these require new software. They require the willingness to spend twenty minutes with the documentation of tools you already use daily — and the payoff compounds every time you reach for them instead of installing yet another dependency.

All Articles

Related Articles

The Script Nobody Can Read: Undocumented Automation as Institutional Risk

The Script Nobody Can Read: Undocumented Automation as Institutional Risk

Run It Twice, Trust It Once: Engineering Scripts That Survive Repeated Execution

Run It Twice, Trust It Once: Engineering Scripts That Survive Repeated Execution

Why Your Automation Scripts Get Slower Every Month (And What You Can Actually Do About It)

Why Your Automation Scripts Get Slower Every Month (And What You Can Actually Do About It)