Hacker News new | ask | show | jobs
by heynowheynow 1327 days ago
sed, grep, and find are radically different on macOS (4.4BSD + early FreeBSD + many hacks since).
1 comments

Once upon a time I was writing a few portable shell scripts for Solaris and Linux distros. Limiting the scripts to a common subset of commands was fighting windmills - so often you stuck with something easily solved by one GNU option, but requiring 10+ lines of shell script with UNIXy commands on Solaris.

In the end, it was much easier to just proclaim GNU coreutils as a dependency everywhere, and use g-prefixed versions of commands (gfind, ggrep, and so on).

Even the GNU commands on Solaris were so old, and from a time where so many were changing and flakey. I could reliably make the Solaris and early Linux bash and gsed segfault. Options weren’t consistent with Linux distros or coreutils from eg ports on FreeBSD. I still have a bias against GNU from those battle scars.

I had to stick to (most of) POSIX across Unixes with ksh88/mksh/pdksh back in the day when my work had to be portable across Linux, BSD, Solaris, HP-UX, and AIX. I could rely on process substitution, etc. but stay vanilla outside the shell itself.

Honestly the only really annoying thing to me was that sed -i didn’t mean in place, but even then it wasn’t reliably atomic IIRC.

Handling the actual OS commands was much harder. Separate commands instead of getent (maybe getpw was one?) on HP-UX pops into my head.