From owner-svn-src-all@FreeBSD.ORG Tue Aug 3 22:17:30 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0AA76106566C; Tue, 3 Aug 2010 22:17:30 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id D44E98FC1A; Tue, 3 Aug 2010 22:17:29 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o73MHTKG077115; Tue, 3 Aug 2010 22:17:29 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o73MHTSK077084; Tue, 3 Aug 2010 22:17:29 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201008032217.o73MHTSK077084@svn.freebsd.org> From: Jilles Tjoelker Date: Tue, 3 Aug 2010 22:17:29 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r210829 - in head: bin/sh tools/regression/bin/sh/builtins X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 Aug 2010 22:17:30 -0000 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)