[Toybox] The "var=value function" shell issue.

Rob Landley rob at landley.net
Sun Jun 9 16:08:08 PDT 2019


I've reached the part of the posix shell stuff (section 2.9.1: simple commands)
that specifies this behavior, and posix is wrong:

  If no command name results, or if the command name is a special built-in or
  function, variable assignments shall affect the current execution environment.
  Otherwise, the variable assignments shall be exported for the execution
  environment of the command and shall not affect the current execution
  environment except as a side-effect of the expansions performed in step 4.

A) This is not what bash does, or has ever done:

  $ hello() { echo boing=$BOING; }
  $ BOING=123 hello
  $ echo $BOING
  $

B) doing it would be STUPID because there's no reason to DO an assignment on the
same line rather than on the previous line unless you want to constrain the
lifetime of the variables. (The semicolon character exists, you can do X=y; echo
$X; It's literally one extra character.)

Rob



More information about the Toybox mailing list