From owner-cvs-src-old@FreeBSD.ORG Tue Dec 28 21:29:50 2010 Return-Path: Delivered-To: cvs-src-old@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8437B106564A for ; Tue, 28 Dec 2010 21:29:50 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 56DB78FC08 for ; Tue, 28 Dec 2010 21:29:50 +0000 (UTC) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.4/8.14.4) with ESMTP id oBSLToDq075133 for ; Tue, 28 Dec 2010 21:29:50 GMT (envelope-from jilles@repoman.freebsd.org) Received: (from svn2cvs@localhost) by repoman.freebsd.org (8.14.4/8.14.4/Submit) id oBSLToRH075132 for cvs-src-old@freebsd.org; Tue, 28 Dec 2010 21:29:50 GMT (envelope-from jilles@repoman.freebsd.org) Message-Id: <201012282129.oBSLToRH075132@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: svn2cvs set sender to jilles@repoman.freebsd.org using -f From: Jilles Tjoelker Date: Tue, 28 Dec 2010 21:27:08 +0000 (UTC) To: cvs-src-old@freebsd.org X-FreeBSD-CVS-Branch: HEAD Subject: cvs commit: src/bin/sh eval.c expand.c expand.h src/tools/regression/bin/sh/expansion cmdsubst7.0 X-BeenThere: cvs-src-old@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: **OBSOLETE** CVS commit messages for the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Dec 2010 21:29:50 -0000 jilles 2010-12-28 21:27:08 UTC FreeBSD src repository Modified files: bin/sh eval.c expand.c expand.h Added files: tools/regression/bin/sh/expansion cmdsubst7.0 Log: SVN rev 216778 on 2010-12-28 21:27:08Z by jilles sh: Don't do optimized command substitution if expansions have side effects. Before considering to execute a command substitution in the same process, check if any of the expansions may have a side effect; if so, execute it in a new process just like happens if it is not a single simple command. Although the check happens at run time, it is a static check that does not depend on current state. It is triggered by: - expanding $! (which may cause the job to be remembered) - ${var=value} default value assignment - assignment operators in arithmetic - parameter substitutions in arithmetic except ${#param}, $$, $# and $? - command substitutions in arithmetic This means that $((v+1)) does not prevent optimized command substitution, whereas $(($v+1)) does, because $v might expand to something containing assignment operators. Scripts should not depend on these exact details for correctness. It is also imaginable to have the shell fork if and when a side effect is encountered or to create a new temporary namespace for variables. Due to the $! change, the construct $(jobs $!) no longer works. The value of $! should be stored in a variable outside command substitution first. Revision Changes Path 1.96 +15 -1 src/bin/sh/eval.c 1.81 +72 -0 src/bin/sh/expand.c 1.15 +1 -0 src/bin/sh/expand.h 1.1 +31 -0 src/tools/regression/bin/sh/expansion/cmdsubst7.0 (new)