Hacker News new | ask | show | jobs
by tyingq 1823 days ago
Similar for other tools. "Awk" on MacOS is mawk, which is significantly different from the gawk that Linux uses as "awk".

Edit: As mentioned below, awk is mawk for some Linux distros, gawk for others, and something else on still others :)

2 comments

True, although sometimes mawk is installed, as others mention.

If you need gawk, put gawk in your shebang, and if nothing else the end user has a chance at understanding why they’re seeing a crash. Also it will crash on line 1, nice and loud.

Which linux are you referring to? I'm almost certain than Ubuntu 16.04 and 18.04 both ship with mawk as the default.

Edit: just checked and my vps than runs 20.10 uses gawk

Edit 2: 18.04 also comes with gawk, at least the install I have. I know I have worked with mawk on a linux machine- could it have been Ubuntu 16.04?

IIRC (no Ubuntu VM handy right now) mawk is the default with a minimal LTS install, using alternatives to point awk at it. When you apt install gawk it has a higher priority in alternatives and flips the awk symlinks over to gawk automagically.
> gawk it has a higher priority in alternatives and flips the awk symlinks over to gawk automagically

That must be what happened. I just checked my other machine that had a pretty new install of 20.04 on it, and it does have mawk. I'm happy to see I'm not crazy.

Ah...yeah, I was probably over generalizing when I said that, though it's probably fair to say that gawk is the default awk for many popular Linux distros.
Debian & Ubuntu have moved back and forth between using mawk or gawk several times.

Debian Jessie (circa 2016) used gawk.

Debian Stretch (circa 2017) used mawk.

Today, Debian uses gawk.

Have you flipped the final one? Both my Buster and Bullseye installation only have mawk.

Trying to dig in deeper makes my head explode though. mawk is marked required yet with update-alternatives priority of 5, and gawk is marked optional but with a priority 10. I guess the intention is that mawk is good enough for base installs, but you probably want gawk.

It's definitely hard to track down. Mawk is often way faster than gawk, but gawk has more features (sockets even...crazy) and maybe fewer arbitrary limits.