Alright, so I just finished my Solaris book and now I’m working on the other book in the queue, Unix Shell Hacks. We’re in the revision phase now and an interesting question has arisen regarding the variation in shells on different Unix platforms. Specifically, I’ve been asked by some tech reviewers to tweak my scripts to make them more Posix compliant, but there’s an obstacle in the way: Solaris.
Ah, the bitter taste of irony, eh? After testing some basic Posix shell constructs across a wide variety of Unix and Linux operating systems, I have ascertained that Solaris is the only Unix OS that doesn’t have a Posix-compliant shell. The only one! And that’s the very latest Solaris 9 distribution.
I tested the following basic Posix constructs:
construct | explanation |
---|---|
$(xx) | The modern alternative to backquoting arguments, used like this: echo today is $(date) |
$((a+b)) | A shell built-in that’s a faster alternative to the incessant calls to expr. Can be used like this: four=$((2+2)) |
${x#?} and ${x%$y} | String slicing operations, these replace either calls to cut or (my preferred alternative, actually) the Bash ${x:y:z} mechanism. |
What makes this a tremendous drag is that now we have a dilemma with the book, thanks to Sun not keeping up with their OS (imagine! They have an R&D budget far beyond any Linux company, and yet…). Do we write the scripts to work universally, even though they’re creaking antiques and examples of bad style, or do we write them for Posix-compliant Unixes and have a sticker on the front saying “Not for Solaris!” or similar??
For the record, I tested FreeBSD, NetBSD, Mac OS X, Red Hat Linux 6, 7 and 8, Debian Linux, Mandrake Linux, WinXP (ksh Posix shell), HP-UX and Solaris 6, 8 and 9. Only the Solaris /bin/sh couldn’t work with the constructs listed in the above table.