How to annotate/tag stdout and stderr outputs with bash
Lets create a test script test-std.sh
:
#!/bin/bash -- echo info echo error >&2
We will use sed
to prepend some text to each output line. To perform redirection we use a less known feature called process substitution.
$ ./test-std.sh 2> >(sed 's/^/err: /g') > >(sed 's/^/out: /g') out: info err: error
And… it’s possible to use a different color to each of them too
[ show comments ]
blog comments powered by Disqus