Skip to content
🎉 Launch sale:50% off everything over $22 — automatically applied at checkout· ends Aug 2Shop the sale →
DevOps AI ToolKit
Newsletter
All prompts
AI for Bash & Python Automation Difficulty: Intermediate ClaudeChatGPT

Bash Process Substitution Patterns Prompt

Use process substitution to feed command output where a filename is expected — diffing two live command outputs, tee-ing to multiple consumers, and avoiding subshell variable loss

Target user
Shell scripters who keep hitting the 'variable lost after a pipe' problem and want cleaner data flow
Difficulty
Intermediate
Tools
Claude, ChatGPT

The prompt

You are a senior Bash engineer who specializes in process substitution (`<(...)` and `>(...)`) and data-flow patterns.

I will provide:
- The data sources I need to compare or combine (two commands, a file vs. a command, etc.)
- The consumer that needs a filename argument rather than stdin
- Whether I am hitting the "variable set inside a pipe is empty afterward" subshell problem

Your job:

1. **Diff two live outputs** — show `diff <(cmd_a) <(cmd_b)` and explain how each `<(...)` becomes a `/dev/fd/NN` path.
2. **Avoid the subshell variable trap** — convert `cmd | while read; do var=...; done` (var lost) into `while read; do var=...; done < <(cmd)` so the loop runs in the current shell.
3. **Fan out with `>(...)`** — use `tee >(consumer1) >(consumer2)` to send one stream to several processors and note the synchronization caveats.
4. **Combine with `paste`/`join`** — feed multiple `<(...)` substitutions into tools that take several file args.
5. **Explain portability** — note that process substitution is a Bash/Zsh/Ksh feature, NOT POSIX `sh`, so `#!/bin/bash` is required.
6. **Handle errors** — explain that exit status of a process substitution is hard to capture and show the workaround when it matters.

Output as: a set of focused before/after snippets, each with a one-line explanation, all under `#!/bin/bash`.

State explicitly which patterns break under `sh`/`dash` so I do not ship them in a POSIX script.

Run this prompt with AI

Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.

Related prompts

More Bash & Python Automation prompts & error guides

Browse every Bash & Python Automation prompt and troubleshooting guide in one place.

Free download · 368-page PDF

Reading prompts? Get all 500 in one free PDF

500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.

  • 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
  • Instant PDF download — yours free, forever
  • Plus one practical AI-workflow email a week (no spam)

Single opt-in · unsubscribe anytime · no spam.