#!/usr/bin/env bash tmp=$(mktemp) # tee writes stdin to the file AND passes it through echo "logged line" | tee "$tmp" echo "file now holds:" cat "$tmp" rm -f "$tmp"
write to a file and stdout at once