#!/usr/bin/env bash set -euf -o pipefail # Write to stdout and append to the file exec > >(tee -a file.txt) # (now the rest of your script)