Strange output when using tee in pipe command

Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I had to use the following command in an assignment:
who|tee test|wc -l
The output on my system is below, which implies that 2 users are connected:
2
Why is it I don't get the output of who on the screen, and right after that the output of wc -l? I thought tee wrote the output to the screen and created a file with the same output at the same time?
The output of who is however found in my file "test", but still it doesn't make sense to me.
linux command-line tee
add a comment |Â
up vote
1
down vote
favorite
I had to use the following command in an assignment:
who|tee test|wc -l
The output on my system is below, which implies that 2 users are connected:
2
Why is it I don't get the output of who on the screen, and right after that the output of wc -l? I thought tee wrote the output to the screen and created a file with the same output at the same time?
The output of who is however found in my file "test", but still it doesn't make sense to me.
linux command-line tee
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I had to use the following command in an assignment:
who|tee test|wc -l
The output on my system is below, which implies that 2 users are connected:
2
Why is it I don't get the output of who on the screen, and right after that the output of wc -l? I thought tee wrote the output to the screen and created a file with the same output at the same time?
The output of who is however found in my file "test", but still it doesn't make sense to me.
linux command-line tee
I had to use the following command in an assignment:
who|tee test|wc -l
The output on my system is below, which implies that 2 users are connected:
2
Why is it I don't get the output of who on the screen, and right after that the output of wc -l? I thought tee wrote the output to the screen and created a file with the same output at the same time?
The output of who is however found in my file "test", but still it doesn't make sense to me.
linux command-line tee
edited Oct 22 '17 at 22:40
agc
4,1501935
4,1501935
asked Oct 22 '17 at 22:06
Omnicron
82
82
add a comment |Â
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
2
down vote
accepted
The effect of piping to tee is that whatever your first command writes to its standard output is written to a file (whose name you passed as a command-line argument to tee) as well as written to the standard output of the tee command. If the pipeline doesn't continue and you don't perform any redirections on the tee command, then tee's standard output is that of your shell, usually your terminal.
That's why running who and running who | tee test show the same text on your terminal. The difference with tee you also write it to a file.
If the pipeline continues, as with who | tee test | wc -l, then whatever standard output would have been written to the terminal is sent to the next command in the pipeline instead. This is the wc command and, unlike tee, wc does not copy its input to standard output (or anywhere). Instead it shows statistics. With the -l option it shows just line counts, so that's all you see.
So the reason you see just 2 from who | tee test | wc -l is the same as the reason you see just 2 from who | wc -l. The tee command writes the output of who to a file but it does not cause it to be printed to the terminal unless its standard output is the terminal. By default it usually is, but not when you pipe it to yet another command.
If you've seen a command on the left side of a | whose output is displayed on the terminal rather than being used as input to the next command in the pipeline, then it likely was writing to standard error instead of standard output.
add a comment |Â
up vote
1
down vote
tee duplicates input so it goes to the file and stdout. From there stdout is piped to wc...it becomes stdin for wc. wc just returns counts, the input data it counts isn't echoed.
If you're trying to make sense of it you could think of cmd1 | tee file | cmd2 as having the same effect as this:
cmd1 > file
cat file | cmd2
This isn't what actually happens but from the standpoint of the person executing the command they would appear to be the same (as long as cmd1 is fast enough to give the impression that everything happens almost simultaneously). In reality file is being filled with data at the same time that cmd2 is receiving that data.
add a comment |Â
up vote
0
down vote
To see both who and wc outputs in bash do:
who | tee >(wc -l) test
Output:
me tty7 2017-10-16 18:17 (:0)
1
Along with the contents of test.
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
The effect of piping to tee is that whatever your first command writes to its standard output is written to a file (whose name you passed as a command-line argument to tee) as well as written to the standard output of the tee command. If the pipeline doesn't continue and you don't perform any redirections on the tee command, then tee's standard output is that of your shell, usually your terminal.
That's why running who and running who | tee test show the same text on your terminal. The difference with tee you also write it to a file.
If the pipeline continues, as with who | tee test | wc -l, then whatever standard output would have been written to the terminal is sent to the next command in the pipeline instead. This is the wc command and, unlike tee, wc does not copy its input to standard output (or anywhere). Instead it shows statistics. With the -l option it shows just line counts, so that's all you see.
So the reason you see just 2 from who | tee test | wc -l is the same as the reason you see just 2 from who | wc -l. The tee command writes the output of who to a file but it does not cause it to be printed to the terminal unless its standard output is the terminal. By default it usually is, but not when you pipe it to yet another command.
If you've seen a command on the left side of a | whose output is displayed on the terminal rather than being used as input to the next command in the pipeline, then it likely was writing to standard error instead of standard output.
add a comment |Â
up vote
2
down vote
accepted
The effect of piping to tee is that whatever your first command writes to its standard output is written to a file (whose name you passed as a command-line argument to tee) as well as written to the standard output of the tee command. If the pipeline doesn't continue and you don't perform any redirections on the tee command, then tee's standard output is that of your shell, usually your terminal.
That's why running who and running who | tee test show the same text on your terminal. The difference with tee you also write it to a file.
If the pipeline continues, as with who | tee test | wc -l, then whatever standard output would have been written to the terminal is sent to the next command in the pipeline instead. This is the wc command and, unlike tee, wc does not copy its input to standard output (or anywhere). Instead it shows statistics. With the -l option it shows just line counts, so that's all you see.
So the reason you see just 2 from who | tee test | wc -l is the same as the reason you see just 2 from who | wc -l. The tee command writes the output of who to a file but it does not cause it to be printed to the terminal unless its standard output is the terminal. By default it usually is, but not when you pipe it to yet another command.
If you've seen a command on the left side of a | whose output is displayed on the terminal rather than being used as input to the next command in the pipeline, then it likely was writing to standard error instead of standard output.
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
The effect of piping to tee is that whatever your first command writes to its standard output is written to a file (whose name you passed as a command-line argument to tee) as well as written to the standard output of the tee command. If the pipeline doesn't continue and you don't perform any redirections on the tee command, then tee's standard output is that of your shell, usually your terminal.
That's why running who and running who | tee test show the same text on your terminal. The difference with tee you also write it to a file.
If the pipeline continues, as with who | tee test | wc -l, then whatever standard output would have been written to the terminal is sent to the next command in the pipeline instead. This is the wc command and, unlike tee, wc does not copy its input to standard output (or anywhere). Instead it shows statistics. With the -l option it shows just line counts, so that's all you see.
So the reason you see just 2 from who | tee test | wc -l is the same as the reason you see just 2 from who | wc -l. The tee command writes the output of who to a file but it does not cause it to be printed to the terminal unless its standard output is the terminal. By default it usually is, but not when you pipe it to yet another command.
If you've seen a command on the left side of a | whose output is displayed on the terminal rather than being used as input to the next command in the pipeline, then it likely was writing to standard error instead of standard output.
The effect of piping to tee is that whatever your first command writes to its standard output is written to a file (whose name you passed as a command-line argument to tee) as well as written to the standard output of the tee command. If the pipeline doesn't continue and you don't perform any redirections on the tee command, then tee's standard output is that of your shell, usually your terminal.
That's why running who and running who | tee test show the same text on your terminal. The difference with tee you also write it to a file.
If the pipeline continues, as with who | tee test | wc -l, then whatever standard output would have been written to the terminal is sent to the next command in the pipeline instead. This is the wc command and, unlike tee, wc does not copy its input to standard output (or anywhere). Instead it shows statistics. With the -l option it shows just line counts, so that's all you see.
So the reason you see just 2 from who | tee test | wc -l is the same as the reason you see just 2 from who | wc -l. The tee command writes the output of who to a file but it does not cause it to be printed to the terminal unless its standard output is the terminal. By default it usually is, but not when you pipe it to yet another command.
If you've seen a command on the left side of a | whose output is displayed on the terminal rather than being used as input to the next command in the pipeline, then it likely was writing to standard error instead of standard output.
answered Oct 22 '17 at 22:41
Eliah Kagan
3,16221530
3,16221530
add a comment |Â
add a comment |Â
up vote
1
down vote
tee duplicates input so it goes to the file and stdout. From there stdout is piped to wc...it becomes stdin for wc. wc just returns counts, the input data it counts isn't echoed.
If you're trying to make sense of it you could think of cmd1 | tee file | cmd2 as having the same effect as this:
cmd1 > file
cat file | cmd2
This isn't what actually happens but from the standpoint of the person executing the command they would appear to be the same (as long as cmd1 is fast enough to give the impression that everything happens almost simultaneously). In reality file is being filled with data at the same time that cmd2 is receiving that data.
add a comment |Â
up vote
1
down vote
tee duplicates input so it goes to the file and stdout. From there stdout is piped to wc...it becomes stdin for wc. wc just returns counts, the input data it counts isn't echoed.
If you're trying to make sense of it you could think of cmd1 | tee file | cmd2 as having the same effect as this:
cmd1 > file
cat file | cmd2
This isn't what actually happens but from the standpoint of the person executing the command they would appear to be the same (as long as cmd1 is fast enough to give the impression that everything happens almost simultaneously). In reality file is being filled with data at the same time that cmd2 is receiving that data.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
tee duplicates input so it goes to the file and stdout. From there stdout is piped to wc...it becomes stdin for wc. wc just returns counts, the input data it counts isn't echoed.
If you're trying to make sense of it you could think of cmd1 | tee file | cmd2 as having the same effect as this:
cmd1 > file
cat file | cmd2
This isn't what actually happens but from the standpoint of the person executing the command they would appear to be the same (as long as cmd1 is fast enough to give the impression that everything happens almost simultaneously). In reality file is being filled with data at the same time that cmd2 is receiving that data.
tee duplicates input so it goes to the file and stdout. From there stdout is piped to wc...it becomes stdin for wc. wc just returns counts, the input data it counts isn't echoed.
If you're trying to make sense of it you could think of cmd1 | tee file | cmd2 as having the same effect as this:
cmd1 > file
cat file | cmd2
This isn't what actually happens but from the standpoint of the person executing the command they would appear to be the same (as long as cmd1 is fast enough to give the impression that everything happens almost simultaneously). In reality file is being filled with data at the same time that cmd2 is receiving that data.
edited Oct 22 '17 at 22:40
answered Oct 22 '17 at 22:34
B Layer
3,9241525
3,9241525
add a comment |Â
add a comment |Â
up vote
0
down vote
To see both who and wc outputs in bash do:
who | tee >(wc -l) test
Output:
me tty7 2017-10-16 18:17 (:0)
1
Along with the contents of test.
add a comment |Â
up vote
0
down vote
To see both who and wc outputs in bash do:
who | tee >(wc -l) test
Output:
me tty7 2017-10-16 18:17 (:0)
1
Along with the contents of test.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
To see both who and wc outputs in bash do:
who | tee >(wc -l) test
Output:
me tty7 2017-10-16 18:17 (:0)
1
Along with the contents of test.
To see both who and wc outputs in bash do:
who | tee >(wc -l) test
Output:
me tty7 2017-10-16 18:17 (:0)
1
Along with the contents of test.
edited Oct 22 '17 at 22:36
answered Oct 22 '17 at 22:28
agc
4,1501935
4,1501935
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f399787%2fstrange-output-when-using-tee-in-pipe-command%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password