Jawk 7.0.01
-
Home
- Reference
Compatibility and Compliance
Jawk is checked during mvn verify against 3 upstream compatibility families: POSIX awk specifications[1], One True Awk[2], GNU Awk[3]. This page summarizes what currently passes, fails, errors, or remains intentionally skipped.
POSIX
Specification-focused coverage transcribed from the POSIX awk utility requirements[1].
One True Awk (BWK)
Compatibility coverage derived from the original One True Awk[2] test collection.
GNU Awk (gawk)
GNU Awk[3] compatibility gathered from explicit Java integration suites that mirror the main gawk test families: core behavior, extensions, locale-sensitive behavior, and optional features.
Array and scalar types follow gawk's runtime rules across function parameters and nested array references. An untyped argument remains linked to its caller until its first scalar or array use fixes the type; conflicting assignment, membership, iteration, deletion, or subarray use then fails at runtime.
Detailed Behavior Notes
Date and time functions
The date and time functions (mktime(), strftime()) follow the Java platform's time zone data and calendar rules rather than the C library's, which differs from gawk in a few edge cases:
ENVIRON["TZ"]accepts the zone IDs Java understands: Olson names such asEurope/Paris(optionally with a POSIX:prefix) and Java's customGMT+3IDs with Java's sign convention (GMT+3is UTC+03:00, where POSIX would read UTC-03:00). POSIX TZ rule specifications such asXXX3orCET-1CEST,M3.5.0,M10.5.0/3are not parsed; unknown zones fall back to GMT. An explicitly empty TZ selects UTC, as in POSIX.- An ambiguous wall time during a DST fall-back resolves to its standard-time occurrence; the explicit DST field of
mktime()still selects either occurrence. - A positive
mktime()DST hint applies the zone's current daylight adjustment; zones without daylight saving time ignore the hint. strftime()'s%Zprints the zone's current designation (the JDK's time zone data records historical offsets and DST rules, but not historical zone names), and timestamps before the common era use the JDK's year numbering rather than astronomical (negative) years.
Range patterns
Range patterns (begpat, endpat) evaluate their two conditions lazily, as POSIX requires: the start condition is evaluated only while outside the range, and the end condition only once the range has started — including on the very record that starts it, so a range can begin and end on the same record. Conditions with side effects, such as a++ == 2, a++ == 5, therefore behave exactly as in gawk and One True Awk: each condition's side effects run only on the records where that condition is actually tested.
Where Jawk follows gawk
Jawk follows gawk in several places where gawk departs from historical AWK:
- A regexp literal used as an ordinary expression evaluates as
$0 ~ /re/, per POSIX;x = /re/assigns 0 or 1, not the pattern text. - Typed regexp literals (
@/re/) are accepted;--posixrejects them. IGNORECASEis a built-in special variable managed by the runtime, likeFSorRS: a truthy value makes regexp matching, field andsplit()separators, string comparisons,index(), and gawk array sorting case-insensitive.- Because the gawk compatibility extension[7] is enabled by default,
gensub,typeof,isarray,asort,asorti,mkbool,patsplit,strtonum,systime,mktime,strftime,bindtextdomain,dcgettext, anddcngettextare function names and can no longer be used as variables. Load an explicit extension list withoutGawkExtensionto reclaim those identifiers. - Calling a user-defined function with more arguments than it declares is accepted: the extra expressions are evaluated and discarded, and a gawk-style warning is printed to stderr.
- Assigning a scalar value to an array element (
a[1] = z) types that element as a scalar; later using it as a subarray (a[1][2] = 3) is a runtime error, exactly as in gawk. printandprintfresolve the leading-parenthesis ambiguity as gawk does:print (a, b)prints the parenthesized group as the whole argument list (which is howprint (a, b) > "file"disambiguates a redirection from a comparison), while a single parenthesized expression followed by a comma continues the output list, as inprint (i==0), (i==""), and a group followed byinis a membership key, as inprint (1,2) in a. A comma group followed by more arguments, such asprint (1,2), 3, is a syntax error. More generally, outside of aprint/printfargument list, a parenthesized expression list such as(i, j)is a grouping, not an expression, and is only valid immediately beforein, as in((i, j) in array).
See Also
- [1] https://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html
- [2] https://github.com/onetrueawk/awk
- [3] https://www.gnu.org/software/gawk/
- [4] failsafe.html#io-jawk-posix
- [5] failsafe.html#io-jawk-onetrueawk
- [6] failsafe.html#io-jawk-gawk
- [7] extensions.html#gawk
- [8] behavior-changes.html
- [9] cli-reference.html
- [10] java-compile.html
