Bug 13346

Summary: awk doesn't support calling length() without parentheses
Product: Busybox Reporter: richard.noble
Component: Standard ComplianceAssignee: unassigned
Status: RESOLVED FIXED    
Severity: normal CC: busybox-cvs
Priority: P5    
Version: 1.30.x   
Target Milestone: ---   
Hardware: All   
OS: Linux   
Host: Target:
Build:

Description richard.noble 2020-11-30 11:37:26 UTC
The following should print all lines in /etc/motd that are longer than
50 characters:

$ busybox awk 'length > 50' /etc/motd

Instead you get an error:

awk: cmd. line:1: Unexpected token

If you call length as length() it works:

$ busybox awk 'length() > 50' /etc/motd

Note the following from the GAWK manual:

"NOTE: In older versions of awk, the length() function could be called
without any parentheses. Doing so is considered poor practice, although
the 2008 POSIX standard explicitly allows it, to support historical
practice. For programs to be maximally portable, always supply the
parentheses."

<https://www.gnu.org/software/gawk/manual/html_node/String-Functions.html>

The parens are optional according to the 2018 POSIX standard too:

"length[([s])]
    Return the length, in characters, of its argument taken as a string,
    or of the whole record, $0, if there is no argument."

<https://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html>

(tested on BusyBox v1.30.1 (Debian 1:1.30.1-4))
Comment 1 Denys Vlasenko 2020-11-30 17:24:32 UTC
Fixed in 1.32.x:

commit bd8b05ba1b0901bbd6a913dfd5186ac7c8beffed
Author: Denys Vlasenko <vda.linux@googlemail.com>
Date:   Sun Feb 2 23:28:55 2020 +0100

    awk: fix more "length" cases, closes 12486