Every shell is a loop - print a prompt, read a line, act on it, repeat. Today you build that loop and the way it ends, which is the skeleton every later lesson hangs code on.
Print a prompt, read one line of input at a time, and stop cleanly at end of input.
A shell is a read-eval-print loop: it prints a prompt, reads a line you type, does what the line says, and loops back for the next one. Today only the “read” and “loop” halves exist - there is nothing to evaluate yet - but this loop is the spine of the whole project, so it is worth getting the shape right.
The one subtlety is how the loop ends. When input runs out - the user presses
Ctrl-D at the terminal, or a script file reaches its last line - the read
returns an end-of-input signal rather than a line. That is your cue to leave the
loop and exit 0. Strip the trailing newline from each line as you read it; every
later lesson assumes the line it receives has no \n on the end.
// print a prompt, read a line, repeat until EOFfor (;;) {printf("$ ");if (!read_line(&line)) break; // EOF -> stop// (nothing to do with the line yet)}