有一个简单的bash脚本:
#!/bin/bash
exec 2> >(while read; do echo >&2 -ne '\e[1;36m'; echo >&2 -n "$REPLY"; echo >&2 -e '\e[m'; done)
echo line1
echo errline1 >&2
echo line2
echo errline2 >&2
echo line3
echo err line 3 >&2
第二行旨在为stderr着色。
结果是:
line1
line2
line3
errline1
errline2
err line 3
预期:
line1
errline1
line2
errline2
line3
err line 3