Scalar values in
awk are either numbers or strings.
gawk also supports values of type
(see Strongly Typed Regexp Constants).
As described in True and False in
awk, Boolean values in
don’t have a separate type: a value counts as “true” if it is nonzero
or non-null, and as “false” otherwise.
When interchanging data with languages that do have a real Boolean type,
using a standard format such as JSON or XML, the lack of a true Boolean
awk is problematic.
(See, for example, the
json extension provided by
It’s easy to import Boolean data into
awk, but then the fact
that it was originally Boolean is lost. Exporting data is even harder;
there’s no way to indicate that a value is really Boolean.
To solve this problem,
gawk provides a function named
It takes one argument, which is any
awk expression, and it
returns a value of Boolean type.
The returned values are normal
awk numeric values, with
values of either one or zero,
depending upon the truth
value of the original expression passed in the call to
typeof() function (see Getting Type Information) returns
"number|bool" for these values.
Thus Boolean-typed values are numbers as far as
is concerned, except that extension code can treat them as Booleans
While it would have been possible to add two new built-in variables
of Boolean type named
FALSE, doing so would
undoubtedly have broken many existing
awk programs. Instead,
having a “generator” function that creates Boolean values gives
flexibility, without breaking as much existing code.