View the Most Wanted LQ Wiki articles.
LinuxQuestions.org > Linux Wiki > Stdout

From LQWiki

Jump to: navigation, search

stdout is the standard output stream, usually directed to the user's terminal, though it can also be directed to a file or another program.

All text that is printed normally at a console goes through stdout, though if an error occurs, the program may (the program should) report the message to standard output.

stdout can be directed into a file using the > operator:

ls >file1

puts the output of ls into file1

The content of stdout can be stored in a variable using backticks (`):

scorpio:~ # export v=`echo hallo`
scorpio:~ # echo $v
hallo
scorpio:~ #   

The output of echo has been placed into the variable $v.

The content of stdout can be stored in a variable using the cascadable $() operator:

scorpio:~ # export v=$(ll $(ls /bin/bash))
scorpio:~ # echo $v
-rwxr-xr-x 1 root root 501804 Apr 23 03:46 /bin/bash
scorpio:~ # 

The content of stdout can be redirected to stdin of another program using a pipe:

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

Note that, in this example, echo does not write to the console, but to the input of sed. And sed does not take its input from the keyboard, but from the output of echo. sed 's/hello/hi/' means: replace "hello" by "hi".

See also


Share

Personal tools