sto prendendo uno sguardo al codice per l'utilità 'di meno', in particolare come si arriva input da tastiera. È interessante notare che, sulla linea 80 della ttyin.c, imposta il descrittore di file per leggere da:Meno riceve l'input da tastiera da stderr?
/*
* Try /dev/tty.
* If that doesn't work, use file descriptor 2,
* which in Unix is usually attached to the screen,
* but also usually lets you read from the keyboard.
*/
#if OS2
/* The __open() system call translates "/dev/tty" to "con". */
tty = __open("/dev/tty", OPEN_READ);
#else
tty = open("/dev/tty", OPEN_READ);
#endif
if (tty < 0)
tty = 2;
non è il file descrittore di 2 stderr? Se è così, WTH ?! Pensavo che l'input da tastiera fosse stato inviato tramite stdin.
È interessante notare che, anche se si fa ls -l * | less
, dopo che il file termine del caricamento, è comunque possibile utilizzare la tastiera per scorrere verso l'alto e verso il basso, ma se lo fai ls -l * | vi
, allora vi sarà urlare a voi, perché non legge da stdin . Qual è la grande idea? Come ho fatto a finire in questa strana nuova terra dove stderr è sia un modo per segnalare errori allo schermo e leggere dalla tastiera? Non credo di essere più in Kansas ...
BTW, se scrivi 'ls -l * | vim -', vim eseguirà una magia simile. – ephemient