- Expressions are the basic elements of computation in programs. They are
built from constants, variables, function calls, and combinations of the
various kinds of values with operators.
awk supplies three kinds of constants: numeric, string, and
gawk lets you specify numeric constants in octal
and hexadecimal (bases 8 and 16) as well as decimal (base 10).
In certain contexts, a standalone regexp constant such as
has the same meaning as ‘$0 ~ /foo/’.
- Variables hold values between uses in computations. A number of built-in
variables provide information to your
awk program, and a number
of others let you control how
- Numbers are automatically converted to strings, and strings to numbers,
as needed by
awk. Numeric values are converted as if they were
sprintf() using the format in
Locales can influence the conversions.
awk provides the usual arithmetic operators (addition,
subtraction, multiplication, division, modulus), and unary plus and minus.
It also provides comparison operators, Boolean operators, an array membership
testing operator, and regexp
matching operators. String concatenation is accomplished by placing
two expressions next to each other; there is no explicit operator.
The three-operand ‘?:’ operator provides an “if-else” test within
- Assignment operators provide convenient shorthands for common arithmetic
awk, a value is considered to be true if it is nonzero
or non-null. Otherwise, the value is false.
- A variable’s type is set upon each assignment and may change over its
lifetime. The type determines how it behaves in comparisons (string
- Function calls return a value that may be used as part of a larger
expression. Expressions used to pass parameter values are fully
evaluated before the function is called.
built-in and user-defined functions; this is described in
- Operator precedence specifies the order in which operations are performed,
unless explicitly overridden by parentheses.
precedence is compatible with that of C.
- Locales can affect the format of data as output by an
program, and occasionally the format for data read as input.