if [ -t 1 ]; then
eval "$(printf 'COLOR_ON="3[31m" COLOR_OFF="3[m"')"
else
COLOR_ON= COLOR_OFF=
fi
export COLOR_ON COLOR_OFF
awk '{print ENVIRON["COLOR_ON"] "prefix: " ENVIRON["COLOR_OFF"] $0}'
Ou:
[ ! -t 1 ]
awk -v color="$?" '{
print((color ? "3[31m" : "") "prefix: " (color ? "3[m" : "") $0)}'