Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

expr length "$val" returns the wrong length for values containing NULL (\\0)



Test case:

v=$(printf foo\\0bar);expr length "$v";expr length $v

alternatively:

v=foo$'\0'bar;expr length "$v";expr length $v

In zsh, the values returned are  3 and 3.
In dash and zsh, the values returned are 6 and 6.

Both of those results are wrong, AFAICS (foo$'0'bar is 7 characters long).
But the zsh result is more severely wrong. I could understand the bash/dash
result, at least,  as 'NULL characters are not counted towards length'.

In any case, it is easily demonstrated that the string is not 3 characters
long, by running 'echo "$V"' or 'print "$v"' or 'echo ${#v}'

`zsh --version` = 'zsh 5.2 (x86_64-unknown-linux-gnu)'


Messages sorted by: Reverse Date, Date, Thread, Author