awk
In multiline awk programs/scripts, actions preceded by BEGIN, a predicate (test-action), or END should insert a space before the opening curly brace ({). Single-line actions should insert a space after the opening curly and before the ending curly. Functions should insert a newline before/after the opening/closing curly brace. If the function can be written on a single-line in less than 80 characters, space can be used instead of newline.
1
function abc() { ... }
2
function def()
3
{
4
...
5
}
6
BEGIN { ... }
7
BEGIN {
8
...
9
}
10
{ ... }
11
{
12
...
13
}
14
test { ... }
15
test {
16
...
17
}
18
start, stop { ... }
19
start, stop {
20
...
21
}
22
END { ... }
23
END {
24
...
25
}
Copied!
Localized function variables declared in the argument scope should be preceded by eight (8) spaces to separate them from the intended function arguments. If the arguments and locals together would exceed 79 characters, separate arguments and locals with a newline.
1
function abc(arg1, arg2, local1, local2)
2
{
3
...
4
}
5
function def(arg1, arg2,
6
local1, local2, local3, local4, local5, local6, local7, local8, local9,
7
local10, local11)
8
{
9
...
10
}
11
function ghi(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10,
12
arg11, arg12,
13
local1, local2, local3)
14
{
15
...
16
}
Copied!
Precede functions with intended syntax and description.
1
# add(arg1, arg2)
2
#
3
# Show addition. Returns sum of arg1 and arg2.
4
#
5
function add(arg1, arg2, sum)
6
{
7
sum = arg1 + arg2
8
printf "%u + %u = %u\n", arg1, arg2, sum
9
return int(sum)
10
}
Copied!
Copy link