Sunil Thomas Thonikuzhiyil forced the electrons to say:
> Now I want to redirect the output ( and error) to a file . I want to get
> the output as shown on the screen in a file
> $ ./tt 2>&1 1>output.txt
> ++ echo hello
> ++ set +x
I'd try to be a bit lucid here, but this is one of the issues that
usually vex newbie bash scripters. I think it is also a bash FAQ.
When your program starts, there are 3 fds open, let us say on /dev/stdin,
/dev/stdout and /dev/stderr. Let us go through your command line and
see what happens when bash parses this command line.
2>&1 makes fd 2 to point to the same stream as fd 1. Thus, now your fds
1 and 2 are pointing to /dev/stdout.
1> output.txt makes fd 1 to point to the file output.txt. Where is fd
2 pointing now? To /dev/stdout, and not to the file output.txt.
So how to solve the problem? Just think of the effect of the command line
./tt 1> output.txt 2>&1
and try to visualise what happens when bash parses this.
Now, before bash redirects fd 2 to fd 1, fd 1 is pointing to the file
output.txt. So, fd 2 will also now point to this file.
Actually, this can be resolved by simply
./tty &> output.txt
Binand :-)
--
#define l/* Binand Raj S. <[EMAIL PROTECTED]> */".%\"-\"("
#define s/* Ambition: To write sendmail.cf from scratch */abs(abs(i)-5)
main(i,j){for(i=-5;i<6;i++){for(j=0;j<35-s;j++,putchar(32));putchar(s[l]^
108);for(j=0;j<2*s-1;j++,putchar(32));s&&putchar(s[l]^108);putchar(10);}}
----------------------------------------------
LIH is all for free speech. But it was created
for a purpose. Violations of the rules of
this list will result in stern action.