Table of Contents

Shell Data Processing - Standard Output Stream (stdout)

About

The Standard Output Stream is the output stream of a command

This is a file descriptor linked to a application.

Operation

Create a file from a Standard Output Stream

To create a file from a standard output stream, you use the redirected

Example:

echo 'Hello World' > hello.txt
cat hello.txt
Hello World

Send the Standard Output Stream as the Input Stream of another command

The Standard Output Stream can become the standard input stream of another command with the pipe redirection operator.

Example:

echo Hello World | tr HW hw 
hello world

Redirect Stdout within a block

Redirect Stdout with an anonymous block

{
    cat <<-EOH
       #
       # THIS IS A comment
       #
    EOH
    echo Another
} > "/path/to/file"

/dev/stdout

/dev/stdout is a device file

In other word, /dev/stdout is a link to STDOUT of the process accessing it.

Example:

echo "Hello, World!" > /dev/stdout
foo > /dev/stdout

It represents file descriptor 1.

Most systems provide symbolic links /dev/stdin, /dev/stdout, and /dev/stderr, which respectively link to the files 0, 1, and 2 in /proc/self/fd.

/var/log/stdout

/var/log/stdout is a file that can be used to store and persist the standard output (stdout) of specific processes or services.

They can therefore be analyzed later.

myapp > /var/log/stdout 2>/var/log/stderr

/proc/pid/fd/1

fd is a https://man7.org/linux/man-pages/man5/procfs.5.html subdirectory containing one entry:

Thus:

For example, assuming that -i is the flag designating an input file and -o is the flag designating an output file:

app -i /proc/self/fd/0 -o /proc/self/fd/1 
# same as
app -i /dev/stdin -o /dev/stdout 

/dev/fd/1 (Docker)