mirror / busybox

BusyBox mirror

Home Page:https://www.busybox.net/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

length() in awk's functions

MilaMurry opened this issue · comments

Apparently, when using length() function to get a passed array's length, busybox will return a wrong value.

RIGHT:
$ gawk 'function f(arr) { print length(arr) } BEGIN { arr[1]=0; arr[2]=0; f(arr) }'
2

WRONG:
$ awk 'function f(arr) { print length(arr) } BEGIN { arr[1]=0; arr[2]=0; f(arr) }'
0

Fortunately, passing a string works just fine though.

RIGHT:
$ gawk 'function f(str) { print length(str) } BEGIN {str="abcd"; f(str) }'
4

RIGHT:
$ awk 'function f(str) { print length(str) } BEGIN {str="abcd"; f(str) }'
4

Unfortunately, busybox awk is still return number of bytes instead of characters.

RIGHT:
$ echo 絵 | gawk '{print length}'
1

WRONG:
$ echo 絵 | awk '{print length}'
3

Neither length working on arrays nor locales other than "C" are mandated by POSIX,