It seems read
does not write to standard output.
$ cat test.sh #!/bin/bash read -p "type a key and Enter" key echo "the key was $key" $ ./test.sh type a key and Enterx the key was x $ ./test.sh | tee file type a key and Enterx the key was x $ cat file the key was x
Trying it without a script...
$ read -p "type a key and Enter" key | tee file type a key and Enterx $ cat file $
The read
command is described here. A brief description: "Read a line from standard input".
Information on the pipe, |
, from The Linux Command Line (2nd Internet Edition) by William E. Shotts follows.
Using the pipe operator "|" (vertical bar), the standard output of one command can be piped to into the standard input of another:
command1 | command2
From the man page for tee
is this description:
read from standard input and write to standard output and files
The man page for tee
is at this link.
Where is the list of all the other examples of programs that write to the console but actually do not use standard output, or in the absence of such a list, what is the general rule for knowing when a program that writes to the console is not using standard output?
It seems read
violates the Principle of Least Astonishment.
read
. I'm writing up an answer ATM. – wjandrea Jan 07 '17 at 04:07read
outputs a prompt:type a key and Enter
– wjandrea Jan 07 '17 at 04:09script
for that instead. – wjandrea Jan 07 '17 at 05:51read -p
writes to the standard error stream. See https://www.gnu.org/software/bash/manual/html_node/Bash-Builtins.html#index-read. – David Foerster Jan 07 '17 at 12:19