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