svn commit: r210829 - in head: bin/sh
tools/regression/bin/sh/builtins
Jilles Tjoelker
jilles at FreeBSD.org
Tue Aug 3 22:17:30 UTC 2010
Author: jilles
Date: Tue Aug 3 22:17:29 2010
New Revision: 210829
URL: http://svn.freebsd.org/changeset/base/210829
Log:
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.
Added:
head/tools/regression/bin/sh/builtins/eval5.0 (contents, props changed)
Modified:
head/bin/sh/eval.c
Modified: head/bin/sh/eval.c
==============================================================================
--- head/bin/sh/eval.c Tue Aug 3 22:06:34 2010 (r210828)
+++ head/bin/sh/eval.c Tue Aug 3 22:17:29 2010 (r210829)
@@ -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);
}
Added: head/tools/regression/bin/sh/builtins/eval5.0
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ head/tools/regression/bin/sh/builtins/eval5.0 Tue Aug 3 22:17:29 2010 (r210829)
@@ -0,0 +1,4 @@
+# $FreeBSD$
+
+# eval should return 0 if no command was executed.
+eval $(false)
More information about the svn-src-head
mailing list