summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2010-03-13 22:53:17 +0000
committerjilles <jilles@FreeBSD.org>2010-03-13 22:53:17 +0000
commit6be35ddc1a8fedc3f7f37d3b88f55fc51dd67b33 (patch)
treeef897b5710102607555e0af7bc23332d695b90ab /bin
parenta93ba965a77aac461c3f200b2c61ffd75cfaf937 (diff)
downloadFreeBSD-src-6be35ddc1a8fedc3f7f37d3b88f55fc51dd67b33.zip
FreeBSD-src-6be35ddc1a8fedc3f7f37d3b88f55fc51dd67b33.tar.gz
sh: Do not abort on a redirection error if there is no command word.
Although simple commands without a command word (only assignments and/or redirections) are much like special builtins, POSIX and most shells seem to agree that redirection errors should not abort the shell in this case. Of course, the assignments persist and assignment errors are fatal. To get the old behaviour portably, use the ':' special builtin. To get the new behaviour portably, given that there are no assignments, use the 'true' regular builtin.
Diffstat (limited to 'bin')
-rw-r--r--bin/sh/eval.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/bin/sh/eval.c b/bin/sh/eval.c
index cdd6386..199ec1e 100644
--- a/bin/sh/eval.c
+++ b/bin/sh/eval.c
@@ -680,7 +680,7 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd)
/* Variable assignment(s) without command */
cmdentry.cmdtype = CMDBUILTIN;
cmdentry.u.index = BLTINCMD;
- cmdentry.special = 1;
+ cmdentry.special = 0;
} else {
static const char PATH[] = "PATH=";
int cmd_flags = 0, bltinonly = 0;
@@ -891,6 +891,12 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd)
}
handler = &jmploc;
redirect(cmd->ncmd.redirect, mode);
+ /*
+ * If there is no command word, redirection errors should
+ * not be fatal but assignment errors should.
+ */
+ if (argc == 0 && !(flags & EV_BACKCMD))
+ cmdentry.special = 1;
if (cmdentry.special)
listsetvar(cmdenviron);
commandname = argv[0];
OpenPOWER on IntegriCloud