On 6/10/19 11:38 AM, enh wrote:
> the toybox project is adding a shell, and came across this issue that
> i (Android native tools/libraries maintainer) have hit before because
> mksh does exactly what POSIX says and bash does what POSIX probably
> intended: 
> http://lists.landley.net/pipermail/toybox-landley.net/2019-June/010530.html
> 
> repeated here, lightly edited and extended, because i know there are
> plenty of shell folks here:
> 
> I've reached the part of the posix shell stuff (section 2.9.1: simple 
> commands)
> that specifies this behavior, and posix doesn't match bash:
> 
>   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.

This has been changed in the current published version of POSIX, which
makes the variable persistance behavior unspecified:

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_01


"If the command name is a function that is not a standard utility
implemented as a function, variable assignments shall affect the current
execution environment during the execution of the function. It is unspecified:

    Whether or not the variable assignments persist after the completion of
the function

    Whether or not the variables gain the export attribute during the
execution of the function

    Whether or not export attributes gained as a result of the variable
assignments persist after the completion of the function (if variable
assignments persist after the completion of the function)"



> 
> A) This is not what bash does, or has ever done:
> 
>   $ hello() { echo boing=$BOING; }
>   $ BOING=123 hello
>   $ echo $BOING

While this is true for bash in its default mode, bash implements the
previously-mandated POSIX behavior in POSIX mode:

$ cat x3
set -o posix
hello() { echo boing=$BOING; }
BOING=123 hello
echo after: $BOING
$ ../bash-5.0-patched/bash x3
boing=123
after: 123

I agree that the default bash behavior is more useful and often what is
desired (that's why it's the default), and the next version of bash will
probably make that the default in POSIX mode as well.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    c...@case.edu    http://tiswww.cwru.edu/~chet/

Reply via email to