Thursday, March 17, 2005

Bash - How to append stdout and stderr to the same file?

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 bottom line is >> cannot be used with &.
Post a Comment