On 04/17/2016 08:28 AM, Thomas Schmitt wrote:
Hi,
Jeremy Nicoll wrote:
would anyone ever code:
bin/mailwatcher 2>&1 >/dev/null
when surely all they need is
bin/mailwatcher >/dev/null
Interesting question. (Like what is the use case of cat(1) ?)
Surely this is one of the less useful variations of the rules
for redirection.
Let's assume a subordinate script which expects to get started
with stdout redirected to some non-vanilla target.
For some reason it could decide to direct the stderr of one of
its own sub-subordinate scripts to stdout as prepared by its
superior script and to direct the sub-subordinate stdout to /dev/null.
Superior:
subordinate | result_consumer
Subordinate
...
echo "Note: Switching to diagnostic output mode"
subsubordinate 2>&1 >/dev/null
...
Subsubordinate:
... some (in this case) invalid output to stdout ...
echo "Failed because ..." >&2
...
Have a nice day :)
Thomas
Wow, that's pretty arcane, but pretty cool as well. While understanding
how redirection works, I had never considered such a case. It does
point out the power of the redirection options available, though.
--
Mike