Process Substitution in Shell

Level 498 keystrokes

Process substitution <(command) makes a command's output look like a file. diff compares two detailed directory listings, and a while loop reads app.log as it grows; tail -f never ends, so the loop runs until it is interrupted.

Shell code

# <(ls -la ...) turns each listing into a file-like input; diff prints the differences
1diff <(ls -la dir1) <(ls -la dir2)
# Read the log one line at a time
2while read line; do
# Print each line with a Log: prefix
3 echo "Log: $line"
# tail -f keeps following new lines and never ends, so the loop runs until interrupted
4done < <(tail -f app.log)

Output

1c1
< -rw-r--r-- 1 user user 100 file.txt
---
> -rw-r--r-- 1 user user 200 file.txt
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this Shell code and how often they appear.

  • <× 4
  • -× 3
  • (× 3
  • )× 3
  • "× 2
  • ;× 1
  • :× 1
  • .× 1
  • $× 1

More Shell examples at level 4

← Shell typing practice