linux - Simple tee example -
can please explain why tee works here:
echo "testtext" | tee file1 > file2
my understanding tee duplicates input , prints 1 screen.
the above example allows output echo sent 2 files, first redirecting second.
i expect 'testtext' printed screen , passed through file1 , landing in file2. similar how text in following example end in file2.
echo "testtext" > file1 > file2
can explain missing in understanding?
edit
is because writing file , stdout gets redirected?
your description right: tee receives data stdin , writes both file , stdout. when redirect tee's stdout file, there nothing written terminal because data ended inside second file.
is because writing file , stdout gets redirected?
exactly.
what trying done (demonstrating how tee works):
$ echo "testtext" | tee file1 | tee file2 testtext
but since tee gnu coreutils accepts several output files specified, 1 can just:
$ echo "testtext" | tee file1 file2 testtext
but idea of passed through file1 , landing in file2 not correct. shell example:
echo "testtext" > file1 > file2
makes shell open both files file1
, file2
writing truncates them , since stdout can redirected file directly, last redirection effective (as overrides previous ones).
Comments
Post a Comment