I've done a lot of cross platform tools, there's really two things you want to concern yourself with:
- The core logic/language should be posix compliant, that works fine, avoid bashisms, zsh'isms, etc. This is where POSIX compliance matters, and that's easy to achieve. This becomes particularly important in subshell code.
- Use that core POSIX sh logic as wrapper to test for, detect, then use, the tools you need to carry out the actions. Go from most likely to be there, to least. I don't think I've ever spent any time or effort on theoretical 'it should be there because POSIX said so' coding, I always just test and use what's there. Sure, it adds some lines of code, but if your goal is to always work on everything, then that's how you do it.
Re the 'compress' tool, I can honestly say I'd never even heard of it before this thread, no wonder from the above comments, why should I have, when it's not as good as modern tools that are always installed, or that can be installed easily?
If you get into anything complicated, the odds of your logic working anywhere at anytime declines rapidly, unless you can make it incredibly simple at the base level. Straight sh, yes, that will always work, but once you add in tools, not so much. You can't for example even count on an 'awk' on a system being basic awk, it might be nawk or gawk that has been linked to awk.
Without testing for tools, you will be sad, and you will not succeed in creating something that is truly cross platform/cross os/cross distro.
With this said, you're still going to find systems that don't work, then you have to update the tool to make that situation work by adding more tests and fallbacks, that's just how it is. I've just added a few more for new situations I'd never seen before.
This isn't hard, unless you try to maintain that a standard that GNU/Linux for example barely follows anymore at many levels (systemd? no?, ok,then, let's move on) should do what you want to believe it should do when it doesn't, that's just going to cause you wasted time and pointless frustration.
Note that if you are trying to use nontrivial tools, this gets WAY harder, because you cannot count on any OS at all at that point, you have to test for and handle each variant, each BSD for example is proud that they don't use a distribution of packages, but an OS that includes its own core tools, which means, you can never rely on output or actions being identical across platforms even if the tools have the same name in each variant/os. ps for example is significantly different on OpenBSD, FreeBSD, Linux, and even on busybox, which you might find on wrt firmware for example.
compress
in your nice Debian system using its package manager? – Ned64 Sep 15 '21 at 23:06gzip
which can decompress LZW files (as produced by the ancientcompress
/ncompress
). Some even symlink gzip touncompress
(and sometimes tocompress
too). Decompression of archaic compression formats is good enough for most purposes. For those who really need to create such files, the ncompress package is available:apt-get install ncompress
– cas Sep 16 '21 at 08:42