← Terminal to Agents
Terminal to Agents

When It Goes Wrong — Reading Errors Instead of Fearing Them

15 Sept 2026·6 min read

I have watched a lot of people stop right here. Not at pipes, not at scripts — at the first block of red text. It looks like a wall and it feels like being told off. It is neither. An error message is an address: it tells you where the problem is and usually what it is.

Read the last line first

This is the whole trick and it feels wrong the first few times. When a command prints twenty lines of error, the lines at the top are usually the route it took to get to the problem. The bottom line is the problem. Start there, then read upwards only if you need more.

Then look inside that line for two things: a filename and a number. The number is a line number. Together they are the exact spot. Most error messages are far more specific than they look, once you stop reading them as a paragraph and start reading them as a label.

Errors travel on a separate channel

This one confuses everybody once, and then never again. A command has two separate outputs: normal results, and errors. They both land on your screen, so they look like one stream — but they are not.

ls nosuchfile > out.txt
The arrow catches normal output, so out.txt is empty — and the error still appears on screen.

That is not a bug and nothing was lost. The error went down the other channel, which the plain arrow does not touch. To catch that one you put a 2 in front of the arrow:

ls nosuchfile 2> errors.txt
Now the error goes into the file. I ran both of these — out.txt was empty, errors.txt had the message.
Why this is worth five minutesThe design is on purpose: results and complaints stay apart, so a pipe can carry the results onward while the complaints still reach a human. Once you know there are two channels, "I saved the output but the file is empty" stops being a mystery.

The most misleading error there is

command not found does not mean you typed it wrong, and it does not mean the program is missing. It means the shell looked in its list of folders and did not find it there. That list is called PATH.

echo $PATH
Prints the folders the shell searches, separated by colons. That is the entire list — nothing outside it is findable by name.
which grep
Shows exactly which file runs when you type that name. On my machine: /usr/bin/grep.

These two turn a dead end into a question you can answer. If the program is installed but its folder is not in PATH, the shell genuinely cannot see it — the fix is the folder, not the command. And which is also how you check that the thing running is the thing you think it is, which matters on Windows where the same name can belong to a different program.

Every command leaves a receipt

echo $?
Shows the result code of the command you just ran. 0 means it worked.

Run it right after something and you get a number. Zero means success — which is backwards from what you expect, and worth fixing in your head now. Anything else is a failure, and the number often says which kind. Three I checked on this machine: a search that found something gave 0, the same search finding nothing gave 1, and a name that does not exist at all gave 127.

Why a number matters at allBecause a person can read red text and a program cannot. This code is how a script knows whether to carry on or stop — the difference between a backup that noticed it failed and one that reported success while copying nothing. You will use it in Part 8.
Do this in 60 secondsRun ls nosuchfile and read the error — notice it names the file. Then run echo $? and see a number that is not zero. Then run ls and echo $? again, and see 0. You just read the receipt for a working command and a failing one.
Today’s AI angleThis is precisely how a coding agent works without you watching. It runs a command, reads the error output, checks the result code, and tries something else. That loop is the whole difference between an agent and a script — and it only exists because the terminal reports failure in a way a program can read.

Errors have stopped being a wall. Next: everything you have typed so far disappeared when you closed the window. Time to keep it.

When It Goes Wrong — Reading Errors Instead of Fearing Them · Ali Huzaifa