Is there a simple way to "rewind" /dev/stdin
inside my bash script which already read all or some portion from the input pipe?
Application: I wrote a simple MDA that in part 1, reads a single email from fetchmail line by line, like so:
while read -a linA; do
echo -e "$[++linenum]:${#linA[@]},${linA[*]}" > /dev/null # verbose
[ "${linA[0]}" = "Date:" ] && unset linA[0] && mailDate="${linA[*]}"
[ "${linA[0]}" = "Subject:" ] && unset linA[0] && mailSubject="${linA[*]}"
[ "$mailSubject" = "Courtesy Fill Notification" ] || break # if wrong subject then thank you, we're done with this mail
done
and at the end of processing, I wish to save the entire message into a file, both for debugging, and so that the writer-side of the pipe sees that its entire output had been read, and not return failure (therefore keeping the message as unread in the mailbox).
See Question&Answers more detail:os