Silent mode with a forced-output helper
When VERBOSE is false, send stdout and stderr to /dev/null, and still print forced messages.
18th August 2026
set_verbose_mode() {
exec 3>&1
exec 4>&2
if [[ "${VERBOSE}" = true ]]; then
echo "Verbose output enabled"
else
exec 1>/dev/null
exec 2>/dev/null
fi
}
output() {
if [[ -n $1 ]]; then
if [[ -n $2 ]] && [[ "${2}" = forced ]]; then
echo "$1" 1>&3 2>&4
else
echo "$1"
fi
fi
}
Caveats
Set VERBOSE before calling set_verbose_mode. Use output msg forced for lines that must always show.