Ryan haight
Ryan haight

Reputation: 11

Why doesn't "mycommand >>file1 >>file2" append to both files?

Why does entering:

    date >> log >> file

into BASH only append the date to file and doesn't affect log?

Upvotes: 1

Views: 39

Answers (2)

John Moon
John Moon

Reputation: 924

To add on to Rici's answer, you can append to both files using tee:

date | tee -a log file

Upvotes: 1

rici
rici

Reputation: 241761

Because there is only one stdout. Bash allows you to redirect stdout as many times as you like, but each redirect overrides the previous one, and all redirects are configured before the utility is executed.

This is also true of redirecting stdin. cat < a < b will only print the contents of b, for precisely the same reason.

Upvotes: 4

Related Questions