Streams and Redirection

10. Streams and Redirection#

This chapter deepens the operational side of streams: file descriptors, redirection, append mode, pipeline status, tee, and failure-aware stream handling.

  • Descriptors: Use numeric handles for streams.

  • Redirection: Route output and errors intentionally.

  • Pipelines: Connect commands while preserving failure information.

  • Audit trails: Keep normal output, errors, and reports clear.

  • Robustness: Avoid hiding failures in automation.

Chapter Video

Bash Scripting for Beginners: Complete Guide to Getting Started - Data Streams (Part 11) (28:15) by Learn Linux TV

Hosted on YouTube; property of its original creator, embedded here for educational reference only.

Learning Objectives

By the end of this chapter, you will be able to:

  1. Redirect stdin, stdout, and stderr deliberately.

  2. Use file descriptors in scripts.

  3. Build pipelines that preserve failure information.

  4. Use tee and append redirection for report capture.

  5. Explain why stream separation matters for audit scripts.

Chapter Flow

Glossary

#

Term

Explanation

1

stdin

Standard input, file descriptor 0.

2

stdout

Standard output, file descriptor 1.

3

stderr

Standard error, file descriptor 2.

4

File descriptor

A numeric handle for an open stream.

5

Redirection

Shell syntax for routing streams.

6

Append

Adding output to the end of a file.

7

Pipeline

Commands connected with `

8

PIPESTATUS

Bash array of pipeline command statuses.

9

pipefail

Option that exposes pipeline failures.

10

tee

Command that writes output to both a file and stdout.

11

Null device

The special file /dev/null, which discards data written to it.