Basic

Reading input as a pipe or a name

A tool that reads only names is a tool that cannot be chained. The pipe is the second way in, and the two ways are why a tool has one reader.

What you will see

refuse names pipe and name. Two names is the fix.

About 1 min of reading

Try It

Prove one reader

1

Pipe in

printf 'a\nb\n' | wc -l

Before you run it, say out loud what it will print. Then open the answer.

What it prints
2. The pipe is read to the end, which is once.
2

Name in

printf 'a\nb\n' > /tmp/i.txt; wc -l < /tmp/i.txt

Before you run it, say out loud what it will print. Then open the answer.

What it prints
2. The same answer from the other way is one reader.
3

Refuse no way

printf 'way none\n' | awk '{print ($2=="none") ? "refuse names pipe and name" : "ok"}'

Before you run it, say out loud what it will print. Then open the answer.

What it prints
refuse names pipe and name. Two names is the fix.

Data Flow

Two ways in to one reader
1 The way in is decided from the words
↓
2 A name is opened once
↓
3 A pipe is read to the end once
↓
4 No way in refuses with both names
Why this works
Why the input is never opened twice

Twice is two answers, and two answers is a tool that is not a function. A function is the claim of a tool.

The failure at this step

A tool that waits for a pipe that never comes. The refusal is the answer, and the refusal names the ways.

Examples

The way in is decided once

A name or a pipe, one of them. One decision is what makes the reader one function instead of two.

The pipe is read to the end

To the end, once. Once is what makes a second read of the same input impossible.

No way in is refused

The refusal says which ways it accepts. Two names is what makes the fix a word instead of a guess.

Words this lesson uses

Each one is defined here on this site. Open the entry for the full definition and the other words it points at.

← Parsing with a default that is written
Previous Lesson
Parsing with a default that is written
Next Lesson
Two streams, one meaning each
Two streams, one meaning each →