Sample Header Ad - 728x90

Why does unbuffer -p mangle its input?

20 votes
1 answer
1646 views
$ seq 10 | unbuffer -p od -vtc
0000000   1  \n   2  \n   3  \n   4  \n   5  \n   6  \n   7  \n   8  \n
Where did 9 and 10 go?
$ printf '\r' | unbuffer -p od -An -w1 -vtc
  \n
Why was \r changed to \n?
$ : | unbuffer -p printf '\n' | od -An -w1 -vtc
  \r
  \n
$ unbuffer -p printf '\n' | od -An -w1 -vtc
  \r
      \n
WTF?
$ printf foo | unbuffer -p cat
$
Why no output (and a one second delay)?
$ printf '\1\2\3foo bar\n'  | unbuffer -p od -An -w1 -vtc
$
Why no output?
$ (printf '\23'; seq 10000) | unbuffer -p cat
Why does it hang with no output?
$ unbuffer -p sleep 10
Why can't I see what I type (and why is it discarded even though sleep didn't read it)? Incidentally, also:
$ echo test | unbuffer -p grep foo && echo found foo
found foo
How come grep found foo but didn't print the lines that contain it?
$ unbuffer -p ls /x 2> /dev/null
ls: cannot access '/x': No such file or directory
Why didn't the error go to /dev/null? See also https://unix.stackexchange.com/q/521212
$ echo ${(l[foo])} | unbuffer -p cat | wc -c
4095
That's with:
$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux trixie/sid
Release:        n/a
Codename:       trixie
$ uname -rsm
Linux 6.5.0-3-amd64 x86_64
$ expect -c 'puts "expect [package require Expect] tcl [info patchlevel]"'
expect 5.45.4 tcl 8.6.13
$ /proc/self/exe --version
zsh 5.9 (x86_64-debian-linux-gnu)
Same on Ubuntu 22.04 or on FreeBSD 12.4-RELEASE-p5 (except the od commands have to be adapted there, and I get 2321 (all BEL characters there) instead of 4095 above).
Asked by Stéphane Chazelas (579292 rep)
Oct 29, 2023, 03:20 PM
Last activity: Oct 31, 2023, 08:58 PM