Go to the first, previous, next, last section, table of contents.


True and False in @command{awk}

Many programming languages have a special representation for the concepts of "true" and "false." Such languages usually use the special constants true and false, or perhaps their uppercase equivalents. However, @command{awk} is different. It borrows a very simple concept of true and false from C. In @command{awk}, any nonzero numeric value or any non-empty string value is true. Any other value (zero or the null string "") is false. The following program prints `A strange truth value' three times:

BEGIN {
   if (3.1415927)
       print "A strange truth value"
   if ("Four Score And Seven Years Ago")
       print "A strange truth value"
   if (j = 57)
       print "A strange truth value"
}

There is a surprising consequence of the "nonzero or non-null" rule: the string constant "0" is actually true, because it is non-null. (d.c.)


Go to the first, previous, next, last section, table of contents.