#! /bin/bash
exec > >(trap "" INT TERM; sed 's/^/foo: /')
exec 2> >(trap "" INT TERM; sed 's/^/foo: (stderr) /' >&2)
echo foo
echo bar >&2
date
输出结果
foo: foo
foo: (stderr) bar
foo: Fri Apr 27 20:04:34 IST 2018
#! /bin/bash
exec > >(trap "" INT TERM; sed 's/^/foo: /')
exec 2> >(trap "" INT TERM; sed 's/^/foo: (stderr) /' >&2)
echo foo
echo bar >&2
date
输出结果
foo: foo
foo: (stderr) bar
foo: Fri Apr 27 20:04:34 IST 2018