Thursday, March 17, 2005

Bash - Stdout and Stderr redirection to a file (Part two)

What happens when we use >> for redirection. This operator opens the files in append mode and hence there are no issues due to overwriting values.

But try this:
#!/bin/bash

exec >>foo 2>>&1
echo hello >&1
echo boss >&2

Try making it this way:
#!/bin/bash

exec >>foo 2>>1
echo hello >&1
echo boss >&2

Now you see that the file 1 is created with the text boss. So, the bottomline is >> cannot be used with &.

Hope this helps.
Rgds,
Karthick S.

0 comments: