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?
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?
From the command line
script.sh >f.txt 2>&1
or, specific to your output
echo "FooBar" >f.txt 2>&1
For redirecting to stderr, I would use >&2
or >/dev/stderr
. For replicating output, I would use tee
. The drawback of it is that a temporary file is needed:
echo "FooBar" | tee /tmp/stdout >&2 ; cat /tmp/stdout
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, $_;"