2

Command:

echo "a" | tee `tty`

Output:

a

Command:

echo "a" | tee /dev/pts/0

Output:

a
a

File connected with current terminal is /dev/pts/0. Shouldn't both commands produce same output? What am I missing here?

user148865
  • 326
  • 1
  • 5
  • 19

1 Answers1

2

tee duplicates stdin to all file descriptors given on the command line and to stdout, so if one of the files it the current terminal (you can also use -) then input will be written twice on stdout.

In the first case, stdin is not connected to a tty (but to the output of the echo command), so tty gives not a tty. So the command becomes echo "a" | tee not a tty, and you will have three files (called "not" "a" and "tty") each containing "a", as well as "a" written to stdout.

Ruth Franklin
  • 365
  • 3
  • 2