Dynamic Typing (The GNU Awk User’s Guide)
From Get docs
Gawk/docs/latest/Dynamic-Typing
Previous: Return Statement, Up: User-defined [Contents][Index]
9.2.5 Functions and Their Effects on Variable Typing
awk
is a very fluid language. It is possible that awk
can’t tell if an identifier represents a scalar variable or an array until runtime. Here is an annotated sample program:
function foo(a) { a[1] = 1 # parameter is an array } BEGIN { b = 1 foo(b) # invalid: fatal type mismatch foo(x) # x uninitialized, becomes an array dynamically x = 1 # now not allowed, runtime error }
In this example, the first call to foo()
generates a fatal error, so awk
will not report the second error. If you comment out that call, though, then awk
does report the second error.
Usually, such things aren’t a big issue, but it’s worth being aware of them.