The "loop and a half"

Marko Rauhamaa marko at pacujo.net
Thu Oct 5 18:57:51 EDT 2017


Gregory Ewing <greg.ewing at canterbury.ac.nz>:

> bartc wrote:
>> Yes, I tried typing 'sort' in Linux, where it apparently hangs (same
>> on Windows actually). The reason: because it might have killed
>> someone to have added a message saying what you are expected to type
>> and how to end it. (Namely, press Ctrl-D start at the start of a line
>> in Linux, and Ctrl-Z followed by Enter, I think also at the start, in
>> Windows.)
>
> How to signal EOF from the keyboard is a fundamental piece of
> knowledge about the OS. It's not the responsibility of individual
> programs to teach it to you, any more than it's your car's
> responsibility to explain what the steering wheel does each time you
> start the engine.

Gladly, there is an individual program that *does* teach it to you on
Linux. Just give the command:

   stty -a

and you will see (among other things):

   [...]; eof = ^D; [...]

It is actually the terminal driver/emulator that gives Ctrl-D its
special meaning in accordance with how it has been configured.

As for informational messages, it is part of deep-seated Unix culture to
have quiet commands. The purpose of the silence is so you can easily
compose new commands out of existing commands via pipelines and scripts.
It would be inconvenient if you typed the command:

    grep ython message.txt | sort

and the sort command instructed you to press Ctrl-D.


Marko



More information about the Python-list mailing list