Basic

What a command line tool is for

A tool is a promise about two things. The promise is about the words it is given and the answer it writes, and a promise that is written is a promise a reader can check.

What you will see

0. Zero is the promise kept, which is what a script checks.

About 1 min of reading

Try It

Prove the three parts

1

Give the words

printf 'count file=a.txt\n' > /tmp/w.txt; wc -w < /tmp/w.txt

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

What it prints
3. Three words is the input, which is given.
2

Write the answer

printf '42\n' | wc -c

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

What it prints
3. The answer is written, which is what a pipe reads.
3

Write the number

printf 'ok\n' > /dev/null; echo $?

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

What it prints
0. Zero is the promise kept, which is what a script checks.

Data Flow

Words to an answer and a number
1 The words are given to the tool
↓
2 The tool reads the words as a shape
↓
3 The answer is written as text
↓
4 The number is written as the exit
Why this works
Why a tool never asks

Asking is a pause, and a pause is what makes a script hang. A tool that never asks is a tool a script can run.

The claim of this subject

Words in, answer out, number back. Three parts, and three parts is what every later lesson shapes.

Examples

The words are the input

The words are given by a person. Given words are words that must be refused when they are wrong.

The answer is the output

The answer is written, not shown. Written is what a later command reads, and a later command is the test.

The promise is the exit code

Zero is the promise kept. A number is what a script checks, and a script is a reader.

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.

Next Lesson
Arguments as a written shape
Arguments as a written shape →