• Streams

    Streams allow us to pass information from one process to another, there are three streams:

    • 0 - STDIN
      • Standard input is used by the CLI to take user input.
    • 1 - STDOUT
      • Standard output is used to print output.
    • 2 - STDERR
      • Standard error is used to print error messages.

    These streams can be used for also taking input from a file, sending output to a file and similar tasks - one of the ones we are going to discuss is suppressing error messages.

    In this example the script “stderr.sh” is run, this script simply outputs the message “This is an error” to STDERR, the first time it is ran, no stream redirection is applied and thus we see the message, however the second time “2>/dev/null” was appended which means redirect STDERR to /dev/null (this is a special device that accepts input and bins it).

    Streams

    As stated, we can also use this principle to pass information from one program to another:

    Streams

    Here we pass the output (STDOUT) from the “stderr.sh” script to the input (STDIN) of the program grep.