This question already has an answer here:
Whenever I use a pager like
less or an editor like
nano in the shell (my shell is GNU bash), I see a behaviour I cannot explain completely and which differs to the behaviour I can observe with other tools like
ls. I would like to ask how this behaviour comes about.
The —not easy to explain— behaviour is that normally all output to stdout/stderr ends up being recorded in the terminal-emulators backbuffer, so I can scroll back, while (not so normally to me) in the case of using
nano, output is displayed by the terminal-emulator, yet upon exiting the programs, the content "magically disappears".
I would like to give those two examples:
seq 1 200(produces 200 lines in the backbuffer)
seq 1 200 | less(lets me page 200 lines, yet eventually "cleans up" and nothing is recorded in the backbuffer)
My suspicion is that some sort of escape codes are in play and I would appreciate someone pointing my to an explanation of this observed behavioural differences.
Since some comments and answers are phrased, as if it was my desire to change the behaviour, this "would be nice to know", but indeed the desired answer should be the description of the mechanism, not as much the ways to change it.