Référence rapide

Substitution de processus Shell et tubes nommés (FIFO) Antisèche

Guide de référence rapide pour la substitution de processus Shell et les tubes nommés FIFO : commande mkfifo, syntaxe de processus et flux.

· Publié le

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

Sujets associés