Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 28 Dec 2010 21:27:08 +0000 (UTC)
From:      Jilles Tjoelker <jilles@FreeBSD.org>
To:        cvs-src-old@freebsd.org
Subject:   cvs commit: src/bin/sh eval.c expand.c expand.h src/tools/regression/bin/sh/expansion cmdsubst7.0
Message-ID:  <201012282129.oBSLToRH075132@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help

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)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201012282129.oBSLToRH075132>