I'd like to have the stdout of a command replicated to stderr as well under bash. Something like:
$ echo "FooBar" (...) FooBar FooBar $
where (...) is the redirection expression. Is that possible?
Use tee with /dev/stderr:
echo "FooBar" | tee /dev/stderr
or use awk/perl/python to manually do the replication:
echo "FooBar" | awk '{print;print > "/dev/stderr"}' echo "FooBar" | perl -pe "print STDERR, $_;"
Use process substitution: http://tldp.org/LDP/abs/html/process-sub.html
echo "FooBar" | tee >(cat >&2)
Tee takes a filename as parameter and duplicates output to this file. With process substitution you can use a process instead of filename >(cat)
and you can redirect the output from this process to stderr >(cat >&2)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With