빠른 참조

Shell 프로세스 치환 및 FIFO 명명된 파이프 치트시트

Shell 프로세스 치환 문법 및 mkfifo를 활용한 FIFO 명명된 파이프(named pipe) 프로세스 간 스트리밍 퀵 가이드.

· 게시일

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

관련 주제