diff options
| -rw-r--r-- | bin/sh/eval.c | 8 | ||||
| -rw-r--r-- | tools/regression/bin/sh/errors/redirection-error4.0 | 7 |
2 files changed, 14 insertions, 1 deletions
diff --git a/bin/sh/eval.c b/bin/sh/eval.c index cdd638652225..199ec1e3a3ee 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]; diff --git a/tools/regression/bin/sh/errors/redirection-error4.0 b/tools/regression/bin/sh/errors/redirection-error4.0 new file mode 100644 index 000000000000..206097478e35 --- /dev/null +++ b/tools/regression/bin/sh/errors/redirection-error4.0 @@ -0,0 +1,7 @@ +# $FreeBSD$ +# A redirection error should not abort the shell if there is no command word. +exec 2>/dev/null +</var/empty/x +</var/empty/x y=2 +y=2 </var/empty/x +exit 0 |
