Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
sh emulation POSIX non-conformances (Was: [PATCH] Document imperfections in POSIX/sh compatibility)
- X-seq: zsh-workers 48498
- From: Stephane Chazelas <stephane@xxxxxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: sh emulation POSIX non-conformances (Was: [PATCH] Document imperfections in POSIX/sh compatibility)
- Date: Sun, 11 Apr 2021 18:57:26 +0100
- Archived-at: <https://zsh.org/workers/48498>
- In-reply-to: <CAH+w=7a6sjNJsDv4KJyW-o45+Q7GNEp7_TL4LGd-os1ozF8T9A@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- Mail-followup-to: Zsh hackers list <zsh-workers@xxxxxxx>
- References: <7FD930F4-37CD-402B-9A06-893818856199@dana.is> <CAH+w=7aAZKpT0f5LT7RaoCehyO6UZe6FimzuQqOP4o=+EwZs2w@mail.gmail.com> <F56FD538-0428-4D03-BBE2-6E53154EC0EA@dana.is> <CAH+w=7a6sjNJsDv4KJyW-o45+Q7GNEp7_TL4LGd-os1ozF8T9A@mail.gmail.com>
Some non-POSIX conformances I can think of ATM:
* "echo -" does not output -\n
last (or one of the last) time it was brought up, I pointed
out that anyway few shells were POSIX compliant in that regard
in that for instance POSIX requires "echo -e" to output
"-e\n".
I've since asked POSIX allow echo -e, echo -E (and
combinations of those and -n), and zsh's echo -. They've
rejected the latter part. See
https://www.austingroupbugs.net/view.php?id=1222
So I think it would make sense now to stop accepting "-" as
option delimiter in sh emulation.
* a few of zsh's reserved words are still available in POSIX
mode.
$ zsh --emulate sh -c 'foreach() { true; }'
zsh:1: parse error near `()'
$ zsh --emulate sh -c 'end() { true; }'
zsh:1: parse error near `end'
* IFS treated as separator and not delimiter:
$ a='a:b:' zsh --emulate sh -c 'IFS=:; printf "<%s>\n" $a'
<a>
<b>
<>
(POSIX requires <a> and <b> only). Many shells used to behave
like zsh, but switched for POSIX compliance even though the
zsh behaviour is more useful for instance to break down
variables like $PATH (like /bin:/usr/bin: which should be
split into "/bin", "/usr/bin" and "").
* whitespace characters other than SPC/TAB/NL not treated as IFS
whitespace.
$ a=$'\ra\r\rb' zsh --emulate sh -c $'IFS=\r; printf "<%s>\n" $a'
<>
<a>
<>
<b>
POSIX requires only <a> and <b> above as isspace('\r') is
true so \r should receive the same treatment as space, \t, \n.
Few shells do it. bash has only started recently doing it and
only for single byte characters (so is not POSIX either).
--
Stephane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author