awk: unable to define user's function

I can't define user function in awk.
Code:
#!/bin/sh

awk '{
print

function foo() {
    print "foo"
}

foo
}' /dev/null

I get error:
Code:
awk: syntax error at source line 4
 context is
         >>> function <<<  foo() {
awk: illegal statement at source line 5
awk: syntax error at source line 9

Man pages state:
Functions may be defined (at the position of a pattern-action state-
ment) thus:

function foo(a, b, c) { ...; return x }

Parameters are passed by value if scalar and by reference if array
name; functions may be called recursively. Parameters are local to the
function; all other variables are global. Thus local variables may be
created by providing excess parameters in the function definition.

So where is the problem?
Code:
awk version 20110810 (FreeBSD)
 
Thanks. This works.
The point is, that function mustn't be declared inside of a curly brackets.
Duh! I've been pulling my hair out!
 
Back
Top