how to redirect verbose to file?
Cameron Simpson
cs at zip.com.au
Thu Apr 29 02:05:12 UTC 2010
On 28Apr2010 20:23, Dave Ihnat <dihnat at dminet.com> wrote:
| On Thu, Apr 29, 2010 at 10:59:45AM +1000, Cameron Simpson wrote:
| > Then it is excessive. Drop the "2>&1" and it should _still_ work.
| > As mentioned earlier, this incantation is backwards. Redirections are
| > applied left to right, so "2>&1" probably changes nothing.
|
| Hm. Actually, this is very common in Unix/Linux; it indicates
| redirecting the error stream into the stdout stream. If the messages
| are being generated on the stdout stream, you're right.
The redirection indeed sends stderr to stdout.
BUT...
It _then_ sends stdout to a file, and _do_not_ take stderr with it.
Usually what people want is both streams in the file, done like this:
>filename 2>&1
"Send stdout to the file, send stderr to where stdout is now going."
Thus both into the file.
The redirection supplied:
2>&1 >filename
sends stderr to wherever stdout _was_ going, then sends stdout to a
file, leaving stderr _not_ going to the file but to stdout's old
destination.
It boggles my mind that I've seen three separate people recommend
the latter usually-wrong ordering in this thread.
Maybe you're all reading something into the OP's requirements that I
missed?
Observe:
[/home/cameron]janus*255> cat >>foo.sh
echo out >&1
echo err >&2
[/home/cameron]janus*> sh foo.sh
out
err
[/home/cameron]janus*> sh foo.sh >out 2>&1
[/home/cameron]janus*> cat out
out
err
[/home/cameron]janus*> sh foo.sh 2>&1 >out
err
[/home/cameron]janus*> cat out
out
[/home/cameron]janus*>
Is this unexpected?
Cheers,
--
Cameron Simpson <cs at zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/
Draw little boxes with arrows. It helps. - Michael J. Eager
More information about the redhat-list
mailing list