Basic

Parsing with a default that is written

A value that is not given is a value that must be decided. The decision is a default, and a default that is written is a default that the help shows.

What you will see

report defaults used. A hidden default is an invisible decision.

About 1 min of reading

Try It

Print a default and report it

1

Write the defaults

printf 'max 20\nsort none\n' > /tmp/d.txt; wc -l < /tmp/d.txt

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

What it prints
2. Two defaults in one file is a reviewable set.
2

Take a default

printf 'max\n' | grep -f -m 1 /tmp/d.txt | awk '{print $2}'

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

What it prints
20. The missing value took the written default.
3

Report the defaults used

printf 'defaults_used 2\n' | awk '{print ($2>0) ? "report defaults used" : "none"}'

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

What it prints
report defaults used. A hidden default is an invisible decision.

Data Flow

A missing value to a written default
1 The names are read from one file
↓
2 A missing value takes its default
↓
3 The help prints the default with the name
↓
4 The run reports which defaults it used
Why this works
Why the help prints the defaults

A default that is hidden is a decision that is invisible. Invisible is what makes a wrong run look like a right run.

The one default that must be the smallest

The limit. A limit that is large by default is a tool that changes more than a person meant.

Examples

The default is in the help

The help prints the default. Printed is what makes a run that used a default a run a reader knows about.

A default is never a guess

A guess is a value nobody named. A named default is a value that a person can change without opening code.

The written defaults are one file

One file of names and values. One file is what makes the defaults reviewable as a set.

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.

← Arguments as a written shape
Previous Lesson
Arguments as a written shape
Next Lesson
Reading input as a pipe or a name
Reading input as a pipe or a name →