POSIX Portability – Most Portable Between Sed, Awk, Perl, and Sh

portabilityposix

Can someone put these tools in order of portability? Which of these is certain to be found on even the most minimal *nix systems? Is any of them 100% sure to be present? My guess is that the order is the following:

  1. awk
  2. sed
  3. sh
  4. perl

While I imagine there are systems which don't default to a bourne shell, some shell will be present as the default, will that always be at /bin/sh? Presumably not if it's not a bourne-type shell. Both awk and sed have pages explaining them on the POSIX specification so presumably they will always be present. Is that so?
Can I be sure that both will be installed on any *nix? Including embedded systems?

Best Answer

Which is the most portable of sed, awk, perl and sh?

sed, sh and awk are portable being specified by POSIX, perl is not as not being backed by a standard.

Can someone put these tools in order of portability?

If you stick to compliant code, there should be no order of portability for the three POSIX commands.

Which of these is certain to be found on even the most minimal *nix systems?

The three POSIX ones along with many other utilities are mandatory for an OS to be POSIX. OSes lacking some of them due to minimization, or providing incomplete/non-conforming implementations do exist though.

Actually, most (if not all) free and open source Unix like operating systems probably would not pass the conformance process should they try to, and they never try anyway.

Is any of them 100% sure to be present?

I would be surprised to find a *nix like OS lacking a Bourne syntax based shell, but anything is possible, especially with embedded systems.

My guess is that the order is the following: Some shell will be present as the default, will that always be at /bin/sh?

/bin/sh is likely to be a Bourne syntax family shell but is not guaranteed to be POSIX compliant, even en POSIX compliant systems. For example, it is /usr/xpg4/bin/sh on Solaris 10 and older while /bin/sh is the legacy original Bourne shell which is not POSIX.