Skip to content. | Skip to navigation

Navigation

You are here: Home / Support / Guides / Scripting / Bash / Process Substitution

Personal tools

Process Substitution

Making your life easier

The Problem

People are hardwired (somehow) to use backticks for capturing process output:

count=`wc -l *.txt`

A problem here is simply that backticks looks a bit like ticks (depending on your font).

The real problem is if you need to nest process substitutions:

count=`wc -l \`grep -l foo *.txt\``

Note

We'll ignore the problem of dubious filenames causing problems!

The escaping of backticks becomes gradually unreadable.

The Solution

Bash has a much more readable alternative: $( ... ):

count=$(wc -l $(grep -l foo *.txt))

Document Actions