Kurzreferenz

Shell-Prozesssubstitution & Named Pipes (FIFO) Spickzettel

Ein schneller Referenzleitfaden für Shell-Prozesssubstitution und FIFO Named Pipes: mkfifo, Prozesssubstitution und Prozess-Streaming.

· Veröffentlicht

Process Substitution (<() and >())

Process substitution feeds the output of a subshell into a command expecting file path arguments:

# Compare the output of two commands without writing temporary files
diff <(ls ./old_dir) <(ls ./new_dir)

# Compare sorted files directly
diff <(sort file1.txt) <(sort file2.txt)

# Stream command output to compression and hash simultaneously
tee >(gzip > data.gz) >(sha256sum > data.sha) < large_file.tar

FIFO Named Pipes (mkfifo)

A FIFO (First-In-First-Out) special file provides a persistent named pipe on the filesystem:

# 1. Create a named pipe file
mkfifo mypipe

# 2. In Terminal 1 (Consumer blocks until writer connects)
cat < mypipe

# 3. In Terminal 2 (Producer writes to pipe)
echo "Hello via pipe" > mypipe

# 4. Remove the named pipe when done
rm mypipe

References

Verwandte Themen