#!/bin/bash trap 'rm -f fifo' EXIT mkfifo fifo || exit : > fifo & exec 3< fifo read <&3 || echo EOF # A writer opens, writes and closes after the reader has observed EOF but # before the reader closes its end. echo two > fifo && echo "wrote two" # Closing the last open descriptor on the fifo discards the unread data. That # goes for any process, including a reader exiting after EOF. Where it matters, # keep a spare descriptor open. exec 3<&- echo three > fifo & cat fifo