mawk Is Not awk
Today I had occasion to use mawk
instead of awk
with a command that read lines from standard input, manipulates them, and prints them to standard output. Simple enough, or so I thought.
I’ve had this code in production for years. Today I fired it up under mawk
and behold: no output. Wait, there was output, but only after a while. And there it is again!
This is on a fresh install of Debian 12. In that setting, awk
is mawk
, and the program fails as described above. The solution to this puzzle is that mawk
does block buffering rather than line buffering unless you give it the -W interactive
option.
This is genuinely baffling to me. Here you have a program that is line oriented. Traditionally it treats input and output in line-buffered fashion. And yet a derivative version changes that behavior by default.
This is not a new program that has yet to settle into a stable version. And this is a case of changing the basic behaviors of the program. Under those circumstances, the program is different and should have a different name. And it does. Yet it is installed under the traditional name.
Breaking compatibility with past behaviors without changing the program name is simply bad practice. You need a very strong reason to do it. The proper rule of thumb is simple: Don’t do that!