From LQWiki
(Redirected from Standard input)
Jump to navigation Jump to search

stdin is the name for the standard input stream, which is usually read from the keyboard, but possibly coming from a file or another program's output using a pipe. With a pipe ( written | ), you redirect the output stream (stdout) of the left command to the input stream of the right command. Example:

echo "hello" | sed 's/hello/hi/'

In this case, the command echo produces the output "hello". Normally, this output would go to the console, but in this case, it goes as input to the command sed. The command sed would normally get its input from the keyboard, but in this case, it takes the output of the command echo. We say, the input stream of sed has been redirected to the output stream of echo. In this example, the call to sed replaces "hello" by "hi". That is why we get the following result:

scorpio:~ # echo "hello" | sed 's/hello/hi/'
scorpio:~ #    

See also