From: ZyX <kp-pav@yandex.ru>
To: Martijn Dekker <martijn@inlv.org>,
"zsh-workers@zsh.org" <zsh-workers@zsh.org>
Subject: Re: In POSIX mode, ${#var} measures length in bytes, not characters
Date: Sun, 07 Jun 2015 03:34:51 +0300 [thread overview]
Message-ID: <6697841433637291@web4o.yandex.ru> (raw)
In-Reply-To: <55738EFE.1050805@inlv.org>
07.06.2015, 03:29, "Martijn Dekker" <martijn@inlv.org>:
> When in 'emulate sh' mode, ${#var} substitutes the length of the
> variable in bytes, not characters. This is contrary to the standard; the
> length in characters is supposed to be substituted.[*]
>
> Oddly enough, zsh is POSIX compliant here in native mode, but
> non-compliant in POSIX mode.
Do you have a reference where “character” is defined? This behaviour is the same in posh and dash:
% posh -c 'VAR="«»"; echo ${#VAR}'
4
% dash -c 'VAR="«»"; echo ${#VAR}'
4
% zsh -c 'VAR="«»"; echo ${#VAR}' # Non-POSIX mode: length in Unicode codepoints for comparison
2
% locale
LANG=ru_RU.UTF-8
LC_CTYPE="ru_RU.UTF-8"
LC_NUMERIC="ru_RU.UTF-8"
LC_TIME="ru_RU.UTF-8"
LC_COLLATE="ru_RU.UTF-8"
LC_MONETARY="ru_RU.UTF-8"
LC_MESSAGES="ru_RU.UTF-8"
LC_PAPER="ru_RU.UTF-8"
LC_NAME="ru_RU.UTF-8"
LC_ADDRESS="ru_RU.UTF-8"
LC_TELEPHONE="ru_RU.UTF-8"
LC_MEASUREMENT="ru_RU.UTF-8"
LC_IDENTIFICATION="ru_RU.UTF-8"
LC_ALL=
>
> Confirmed in zsh 4.3.11 (Mac OS X), 5.0.2 (Linux) and 5.0.8 (Mac OS X).
>
> $ zsh
> % locale
> LANG="nl_NL.UTF-8"
> LC_COLLATE="nl_NL.UTF-8"
> LC_CTYPE="nl_NL.UTF-8"
> LC_MESSAGES="nl_NL.UTF-8"
> LC_MONETARY="nl_NL.UTF-8"
> LC_NUMERIC="nl_NL.UTF-8"
> LC_TIME="nl_NL.UTF-8"
> LC_ALL=
> % mot=arrêté
> % echo ${#mot}
> 6
> % emulate sh
> % echo ${#mot}
> 8
>
> - Martijn
>
> [*] Reference:
> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02
>> ${#parameter}
>> String Length. The length in characters of the value of parameter
>> shall be substituted. [...]
next prev parent reply other threads:[~2015-06-07 0:41 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-07 0:23 Martijn Dekker
2015-06-07 0:34 ` ZyX [this message]
2015-06-07 1:23 ` Bart Schaefer
2015-06-07 1:27 ` ZyX
2015-06-07 2:21 ` Martijn Dekker
2015-06-09 17:49 ` Martijn Dekker
2015-06-08 8:44 ` Peter Stephenson
2015-06-09 2:19 ` Martijn Dekker
2015-06-09 8:35 ` Peter Stephenson
2015-06-09 15:37 ` Bart Schaefer
2015-06-09 15:43 ` Peter Stephenson
2015-06-11 11:23 ` Daniel Shahaf
2015-06-11 11:33 ` Peter Stephenson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6697841433637291@web4o.yandex.ru \
--to=kp-pav@yandex.ru \
--cc=martijn@inlv.org \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).