summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2010-08-03 22:17:29 +0000
committerjilles <jilles@FreeBSD.org>2010-08-03 22:17:29 +0000
commit184699830c5d6a596fdd993ea7f0c1a75283aae1 (patch)
treeeef8a00dc349a605166c3a9e8d248bb1c4c1cb2a /bin
parent25440e11e9a883c573d37a45aa87b288eb8d7368 (diff)
downloadFreeBSD-src-184699830c5d6a596fdd993ea7f0c1a75283aae1.zip
FreeBSD-src-184699830c5d6a596fdd993ea7f0c1a75283aae1.tar.gz
sh: Return 0 from eval if no command was given.
This makes a difference if there is a command substitution. To make this work, evalstring() has been changed to set exitstatus to 0 if no command was executed (the string contained only whitespace). Example: eval $(false); echo $? should print 0.
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 e2f66ed..ebbe4f7 100644
--- a/bin/sh/eval.c
+++ b/bin/sh/eval.c
@@ -145,7 +145,8 @@ evalcmd(int argc, char **argv)
p = grabstackstr(concat);
}
evalstring(p, builtin_flags & EV_TESTED);
- }
+ } else
+ exitstatus = 0;
return exitstatus;
}
@@ -160,9 +161,11 @@ evalstring(char *s, int flags)
union node *n;
struct stackmark smark;
int flags_exit;
+ int any;
flags_exit = flags & EV_EXIT;
flags &= ~EV_EXIT;
+ any = 0;
setstackmark(&smark);
setinputstring(s, 1);
while ((n = parsecmd(0)) != NEOF) {
@@ -171,11 +174,14 @@ evalstring(char *s, int flags)
evaltree(n, flags | EV_EXIT);
else
evaltree(n, flags);
+ any = 1;
}
popstackmark(&smark);
}
popfile();
popstackmark(&smark);
+ if (!any)
+ exitstatus = 0;
if (flags_exit)
exitshell(exitstatus);
}
OpenPOWER on IntegriCloud