Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
expr length "$val" returns the wrong length for values containing NULL (\\0)
- X-seq: zsh-workers 37368
- From: D Gowers <finticemo@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: expr length "$val" returns the wrong length for values containing NULL (\\0)
- Date: Thu, 10 Dec 2015 12:22:16 +1030
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=QfS0Fe5wdqZ8ZE92foVWVkAu/r6ZO2gwrOfpOrZOyCM=; b=q0wnoukTb0xm/rCPzgf9AszndYe5011gN1V66TQ5clGE75UVNFlkRwcadC2UgswWUY 1bGcKMs97ln4ljcGjeTsjQjyZWyU1nMfi3fsbC+61IGD8V8wGnA01fMiCxA3d88AHCG4 AjrchUQ2DL0+M8EZcx1GxwEnkZpd5rlqG1zNop673hipbIYIeG3lnOLylKP88Q0k/avi whny/7dp9tba2NIQy74bFUUh9vV9vXYCBUcCjYvIK/T7WlA7MB0fosnerttR55boKO7Y YkEOo1IFuB6cdE3ej/2aRcnqBoPR9U/GrBui++FQ0fQ8SVK+sBXWaCH9yp68uv1RV1Rw NqBw==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
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