1

I'm trying to display progress, and make it usable under less:

while true; do echo -n .; sleep 1; done | less

Is there a way to make it work?

2

The output from the echo in the while loop is always unbuffered. If you remove the -n option, you will see the lines containing the dots appearing each second.

It seems that less always tries to read a complete line and won't display it until it reaches end of line or end of file. There doesn't seem to be an option to change that.

  • Are you sure it has to do specifically with less, not with piping in general? – x-yuri Oct 23 '18 at 0:00
  • 2
    @x-yuri why don't you try it yourself: while echo -n .; do sleep 1; done | cat | cat | cat | cat ;-) – mosvy Oct 23 '18 at 0:03
  • 1
    Yes, I'm really sure that a command in a shell pipe will write it's output before it terminates, because there can't be a user mode buffer after the program exits. And the echo command, although a shell builtin, behaves the same as an external command. – RalfFriedl Oct 23 '18 at 0:16
  • Well, I rather meant that maybe it has something to do with libc buffering the communication. But judging from strace output it succeeds (doesn't block) in reading each coming "." character, but doesn't display them for one or another reason. – x-yuri Oct 23 '18 at 9:37
  • Oh, there's a similar question. – x-yuri Oct 23 '18 at 9:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.