Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: sh compatibility issue
On Fri, 4 Mar 2011 14:36:34 +0100
Jilles Tjoelker <jilles@xxxxxxxx> wrote:
> Although 'command' is often implemented as some sort of precommand
> modifier, the POSIX specification says it is a regular builtin,
> therefore redirection errors are not fatal (and variable assignments do
> not persist). The specification also says that 'command' causes operand
> (syntax) errors to be non-fatal.
This should fix at least some such problems.
Index: Src/exec.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/exec.c,v
retrieving revision 1.191
diff -p -u -r1.191 exec.c
--- Src/exec.c 23 Feb 2011 09:47:06 -0000 1.191
+++ Src/exec.c 6 Mar 2011 20:25:15 -0000
@@ -2324,7 +2324,7 @@ execcmd(Estate state, int input, int out
int nullexec = 0, assign = 0, forked = 0;
int is_shfunc = 0, is_builtin = 0, is_exec = 0, use_defpath = 0;
/* Various flags to the command. */
- int cflags = 0, checked = 0, oautocont = -1;
+ int cflags = 0, orig_cflags = 0, checked = 0, oautocont = -1;
LinkList redir;
wordcode code;
Wordcode beg = state->pc, varspc;
@@ -2416,6 +2416,7 @@ execcmd(Estate state, int input, int out
checked = !(cflags & BINF_BUILTIN);
break;
}
+ orig_cflags |= cflags;
cflags &= ~BINF_BUILTIN & ~BINF_COMMAND;
cflags |= hn->flags;
if (!(hn->flags & BINF_PREFIX)) {
@@ -3298,11 +3299,13 @@ execcmd(Estate state, int input, int out
done:
if (isset(POSIXBUILTINS) &&
- (cflags & (BINF_PSPECIAL|BINF_EXEC))) {
+ (cflags & (BINF_PSPECIAL|BINF_EXEC)) &&
+ !(orig_cflags & BINF_COMMAND)) {
/*
* For POSIX-compatible behaviour with special
* builtins (including exec which we don't usually
* classify as a builtin) we treat all errors as fatal.
+ * The "command" builtin is not special so resets this behaviour.
*/
if (redir_err || errflag) {
if (!isset(INTERACTIVE)) {
Index: Test/A04redirect.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/A04redirect.ztst,v
retrieving revision 1.17
diff -p -u -r1.17 A04redirect.ztst
--- Test/A04redirect.ztst 22 Feb 2011 20:09:20 -0000 1.17
+++ Test/A04redirect.ztst 6 Mar 2011 20:25:15 -0000
@@ -386,6 +386,13 @@
?zsh:2: no such file or directory: /nonexistent/nonexistent
$ZTST_testdir/../Src/zsh -f -o POSIX_BUILTINS -c '
+ command set >/nonexistent/nonexistent
+ echo output'
+0:failed special builtin redir with command prefix, POSIX_BUILTINS
+>output
+?zsh:2: no such file or directory: /nonexistent/nonexistent
+
+ $ZTST_testdir/../Src/zsh -f -o POSIX_BUILTINS -c '
echo >/nonexistent/nonexistent
echo output'
0:failed unspecial builtin redir, POSIX_BUILTINS
--
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/
Messages sorted by:
Reverse Date,
Date,
Thread,
Author