13

This is more or less a follow up question to the following two:

I see that on Solaris 10 (SunOS 5.10), I get the following results:

$ type -a awk
awk is /usr/bin/awk
$ PATH="$(getconf PATH)" type -a awk
awk is /usr/xpg4/bin/awk
awk is /usr/bin/awk
$

On Solaris 10, /usr/bin/awk does not accept POSIX standard Awk syntax such as '!x[$0]++', but /usr/xpg4/bin/awk does. Good enough so far.

However, on Solaris 11, there is only /usr/bin/awk even with getconf PATH. Although there is also nawk and oawk is /usr/bin, these evidently aren't pointed to by symlinks from anywhere.

Knowing that Solaris is POSIX certified, this surprised me.

How can I get a POSIX compliant Awk standardly on Solaris 11 using portable code that will also work on other POSIX-compliant systems? (Or is the only option to check for the existence of nawk or oawk and use one of these if present?)

For that matter, what are nawk and oawk?

Wildcard
  • 36,499
  • /usr/xpg4/bin/awk is not in Solaris 11? nawk is "new awk", an improved AT&T awk. – Kusalananda Apr 21 '17 at 06:23
  • 2
    Watch https://www.mail-archive.com/austin-group-l@opengroup.org/msg00885.html – Stéphane Chazelas Apr 21 '17 at 12:26
  • @StéphaneChazelas AFAIK, only full OS installations are tested and declared conformant when complying. – jlliagre Apr 21 '17 at 12:52
  • @jlliagre, it can't be full OSes (OSes with all optional packages installed) as that wouldn't be practical (there are also packages that are mutually exclusive) and the scope of "optional package" would have to be defined. – Stéphane Chazelas Apr 21 '17 at 13:11
  • @StéphaneChazelas Yes. While Solaris 10 had the concept of entire distribution and effectively installed all packages (outside the unselected locale ones), this is no more the case with Solaris 11. My best guess is the "solaris-large-server" group is used for POSIX compliance tests. – jlliagre Apr 21 '17 at 14:03
  • nawk (new awk) came from the AT&T Toolchest. A group of OSVs licensed the source for nawk, terminfo database + utilities, and a number of other technologies from USL (Unix System Laboratories) as part of the SUS3 conformance effort. – fpmurphy Apr 29 '17 at 05:35

1 Answers1

19

On a full or desktop Solaris 11 installation, there are three awk implementations available, plus some variants:

    /usr/bin/awk           pkg:/system/core-os@0.5.11-0.175.3.1.0.2.0
    /usr/bin/nawk          pkg:/system/core-os@0.5.11-0.175.3.1.0.2.0
    /usr/bin/oawk          pkg:/system/core-os@0.5.11-0.175.3.1.0.2.0

    /usr/gnu/bin/awk       pkg:/text/gawk@3.1.8-0.175.3.0.0.30.0
    /usr/bin/gawk          pkg:/text/gawk@3.1.8-0.175.3.0.0.30.0
    /usr/bin/igawk         pkg:/text/gawk@3.1.8-0.175.3.0.0.30.0
    /usr/bin/pgawk         pkg:/text/gawk@3.1.8-0.175.3.0.0.30.0

    /usr/xpg4/bin/awk      pkg:/system/xopen/xcu4@0.5.11-0.175.3.0.0.30.0

They are all "standard compliant", albeit complying with different standards.

  • /usr/bin/awk is complying with the legacy UNIX awk implementation released in 1977. It is kept first in the default system PATH not to break existing scripts as subsequent awk releases break compatibility. oawk is a synonymous of the awk

  • /usr/bin/nawk is the "new" version of awk, first shipped in SVR3.1 in 1986. Awk POSIX standard was based on this implementation. /usr/xpg4/bin/awk is almost identical to the former, but the one that is formally checked against POSIX conformance validation tests.

  • /usr/gnu/bin/awk, also /usr/bin/gawk is the GNU variant of awk. It aims to comply with most or all of the POSIX standard when the environment variable POSIXLY_CORRECT is set in the environment or when called with the -W posix option but otherwise adds numerous specific own extensions. igawk and pgawk are themselves extensions to gawk, the first one supports include files and the second one supports profiling.

See also the GNU awk history chapter for a lot of useful information.

Only the core-os packages are guaranteed to be present on a Solaris 11 regular installation, thus only oawk/awk and nawk are there. In particular, when you create a new non global zone, it contains by default the solaris-small-server group package so neither the xpg4 nor the gnu awk binaries are available. This is by design. The solaris-small-server group is a minimal start point to which you add the required packages for your applications to properly work. This is more secure and efficient than the previous (Solaris 10) way where everything installed on the global zone was installed on the non global one too so you had to remove unused packages when you wanted to minimize the zone.

To get POSIX awk support a portable way in such a "small server" installation, you need to install the xcu4 package and set you PATH to the POSIX conformant one:

pkg install xcu4
PATH=$(getconf PATH):$PATH

Should for some reason you don't want to install that package, a workaround is to use a "custom" PATH containing nawk as awk, e.g.:

mkdir -p /opt/posix/bin
cp /usr/bin/nawk /opt/posix/bin/awk
PATH=/opt/posix/bin:$PATH

Alternatively, you might install GNU awk and set your PATH to get it first:

pkg install gawk
PATH=/usr/gnu/bin:$PATH

Note that this is not specific to Solaris 11. A similar package grouping was already existing under Solaris 10 and earlier and the POSIX compliant utilities were only installed in the "End User", "Developer" and "Full install" metaclusters. Having a system or a zone installed with the "Core" or "Networking support" metacluster would then have lead to the very same xpg4 missing issue.

Note also that the lack of /usr/xpg4/bin/awk in a Solaris 11 system is not a POSIX compliance failure. Only full Solaris installations are used in the vast majority of tests performed by Oracle and ISVs, including the Open Group certification program. Reduced installations are supported but not qualified.

Should you distribute shell scripts (or applications embedding shell scripts/calling shell commands) for Solaris 11, you just need to define /system/xopen/xcu4 as a dependency in their IPS package and the installer will automatically do what is required for the script to work properly:

depend fmri=pkg:/system/xopen/xcu4 type=require

See https://docs.oracle.com/cd/E53394_01/html/E54820/dependtypes.html

jlliagre
  • 61,204
  • 3
    The lack of a POSIX compliant awk is a POSIX conformance failure. A system that doesn't have a POSIX compliant awk can't run POSIX compliant scripts. Those small-solaris-server are not POSIX let alone Unix systems. And I suppose they're not covered by the certificate Solaris obtained from the Open Group. – Stéphane Chazelas Apr 21 '17 at 14:02
  • 1
    @StéphaneChazelas Yes, these systems are not qualified so are obviously not covered. Same would happen if Solaris is installed on a non qualified hardware. POSIX/Unix compliance is not a prerequisite for Solaris to work properly. Solaris itself makes no use of POSIX utilities when they differ from its own ones. – jlliagre Apr 21 '17 at 14:11
  • @StéphaneChazelas In any case, a POSIX awk is always present on a Solaris system or non global zone so the issue is not about availability but limited to the name of the command (nawk vs awk). https://docs.oracle.com/cd/E53394_01/html/E54763/nawk-1.html – jlliagre Apr 23 '17 at 07:18
  • 1
    nawk is almost POSIX (it doesn't support CONVFMT for instance), but yes, at least that's not as bad as grep (that doesn't have the POSIX -e/-E for instance) or tr (that doesn't have tr a-f A-F). – Stéphane Chazelas Apr 23 '17 at 07:53
  • @StéphaneChazelas Indeed, clarification added to my reply. Thanks. – jlliagre Apr 23 '17 at 08:13